add logging module to engine and add logging-gem to dummy-app
This commit is contained in:
parent
f11517aefa
commit
5bd13563c5
8 changed files with 133 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -20,6 +20,7 @@ rdoc
|
|||
test/dummy/db/*.sqlite3
|
||||
test/dummy/db/*.sqlite3-journal
|
||||
test/dummy/log/*.log
|
||||
test/dummy/log/*.log*
|
||||
test/dummy/tmp/
|
||||
test/dummy/.sass-cache
|
||||
test/dummy/test/fixtures/*.y*ml
|
||||
|
|
|
|||
5
Gemfile
5
Gemfile
|
|
@ -46,3 +46,8 @@ group :development, :test do
|
|||
# test database
|
||||
gem "sqlite3"
|
||||
end
|
||||
|
||||
group :development, :production do
|
||||
# Logging (only for dummy-app, not for the gem)
|
||||
gem "logging-rails", "0.5.0", require: "logging/rails"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -71,6 +71,12 @@ GEM
|
|||
activesupport (>= 4.1.0)
|
||||
i18n (0.7.0)
|
||||
json (1.8.3)
|
||||
little-plugger (1.1.3)
|
||||
logging (2.0.0)
|
||||
little-plugger (~> 1.1)
|
||||
multi_json (~> 1.10)
|
||||
logging-rails (0.5.0)
|
||||
logging (>= 1.8)
|
||||
loofah (2.0.2)
|
||||
nokogiri (>= 1.5.9)
|
||||
macaddr (1.7.1)
|
||||
|
|
@ -81,6 +87,7 @@ GEM
|
|||
mime-types (2.6.1)
|
||||
mini_portile (0.6.2)
|
||||
minitest (5.7.0)
|
||||
multi_json (1.11.1)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
nyan-cat-formatter (0.11)
|
||||
|
|
@ -188,6 +195,7 @@ DEPENDENCIES
|
|||
factory_girl_rails (= 4.5.0)
|
||||
fixture_builder (= 0.4.1)
|
||||
fuubar (= 2.0.0)
|
||||
logging-rails (= 0.5.0)
|
||||
nyan-cat-formatter
|
||||
pry
|
||||
pry-byebug
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
require "diaspora_federation/engine"
|
||||
require "diaspora_federation/logging"
|
||||
|
||||
##
|
||||
# diaspora* federation rails engine
|
||||
module DiasporaFederation
|
||||
extend Logging
|
||||
|
||||
class << self
|
||||
##
|
||||
# the pod url
|
||||
|
|
@ -31,6 +34,7 @@ module DiasporaFederation
|
|||
# end
|
||||
def configure
|
||||
yield self
|
||||
logger.info "successfully configured the federation engine"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
25
lib/diaspora_federation/logging.rb
Normal file
25
lib/diaspora_federation/logging.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
module DiasporaFederation
|
||||
##
|
||||
# logging module for the diaspora federation engine
|
||||
#
|
||||
# it uses the logging-gem if available
|
||||
module Logging
|
||||
private
|
||||
|
||||
##
|
||||
# get the logger for this class
|
||||
#
|
||||
# use the logging-gem if available, else use a default logger
|
||||
def logger
|
||||
@logger ||= begin
|
||||
# use logging-gem if available
|
||||
return ::Logging::Logger[self] if Object.const_defined?("::Logging::Logger")
|
||||
|
||||
# fallback logger
|
||||
@logger = Logger.new(STDOUT)
|
||||
@logger.level = Logger.const_get(Rails.configuration.log_level.to_s.upcase)
|
||||
@logger
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -38,4 +38,10 @@ Rails.application.configure do
|
|||
|
||||
# Raises error for missing translations
|
||||
# config.action_view.raise_on_missing_translations = true
|
||||
|
||||
# Set the logging destination(s)
|
||||
config.log_to = %w(stdout file)
|
||||
|
||||
# Show the logging configuration on STDOUT
|
||||
config.show_log_configuration = true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -48,6 +48,12 @@ Rails.application.configure do
|
|||
# when problems arise.
|
||||
config.log_level = :debug
|
||||
|
||||
# Set the logging destination(s)
|
||||
config.log_to = %w(file)
|
||||
|
||||
# Show the logging configuration on STDOUT
|
||||
config.show_log_configuration = false
|
||||
|
||||
# Prepend all log lines with the following tags.
|
||||
# config.log_tags = [ :subdomain, :uuid ]
|
||||
|
||||
|
|
|
|||
78
test/dummy/config/logging.rb
Normal file
78
test/dummy/config/logging.rb
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
Logging::Rails.configure do |config|
|
||||
# Configure the Logging framework with the default log levels
|
||||
Logging.init %w(debug info warn error fatal)
|
||||
|
||||
# Objects will be converted to strings using the :inspect method.
|
||||
Logging.format_as :inspect
|
||||
|
||||
# The default layout used by the appenders.
|
||||
pattern = "[%d] %-5l PID-%p TID-%t %c: %m\n"
|
||||
layout = Logging.layouts.pattern(pattern: pattern)
|
||||
|
||||
# Setup a color scheme called 'bright' than can be used to add color codes
|
||||
# to the pattern layout. Color schemes should only be used with appenders
|
||||
# that write to STDOUT or STDERR; inserting terminal color codes into a file
|
||||
# is generally considered bad form.
|
||||
Logging.color_scheme("bright",
|
||||
levels: {
|
||||
info: :green,
|
||||
warn: :yellow,
|
||||
error: :red,
|
||||
fatal: %i(white on_red)
|
||||
},
|
||||
date: :blue,
|
||||
logger: :cyan,
|
||||
message: :magenta
|
||||
)
|
||||
|
||||
# Configure an appender that will write log events to STDOUT. A colorized
|
||||
# pattern layout is used to format the log events into strings before
|
||||
# writing.
|
||||
Logging.appenders.stdout("stdout",
|
||||
auto_flushing: true,
|
||||
layout: Logging.layouts.pattern(
|
||||
pattern: pattern,
|
||||
color_scheme: "bright"
|
||||
)
|
||||
) if config.log_to.include? "stdout"
|
||||
|
||||
# Configure an appender that will write log events to a file. The file will
|
||||
# be rolled on a daily basis, and the past 7 rolled files will be kept.
|
||||
# Older files will be deleted. The default pattern layout is used when
|
||||
# formatting log events into strings.
|
||||
Logging.appenders.rolling_file("file",
|
||||
filename: config.paths["log"].first,
|
||||
keep: 7,
|
||||
age: "daily",
|
||||
truncate: false,
|
||||
auto_flushing: true,
|
||||
layout: layout
|
||||
) if config.log_to.include? "file"
|
||||
|
||||
# Setup the root logger with the Rails log level and the desired set of
|
||||
# appenders. The list of appenders to use should be set in the environment
|
||||
# specific configuration file.
|
||||
#
|
||||
# For example, in a production application you would not want to log to
|
||||
# STDOUT, but you would want to send an email for "error" and "fatal"
|
||||
# messages:
|
||||
#
|
||||
# => config/environments/production.rb
|
||||
#
|
||||
# config.log_to = %w[file email]
|
||||
#
|
||||
# In development you would want to log to STDOUT and possibly to a file:
|
||||
#
|
||||
# => config/environments/development.rb
|
||||
#
|
||||
# config.log_to = %w[stdout file]
|
||||
#
|
||||
Logging.logger.root.appenders = config.log_to unless config.log_to.empty?
|
||||
|
||||
# Default log-level (development=debug, production=info)
|
||||
Logging.logger.root.level = config.log_level
|
||||
|
||||
# log-levels for SQL and federation debug-logging
|
||||
Logging.logger[ActiveRecord::Base].level = :debug
|
||||
Logging.logger["XMLLogger"].level = :debug
|
||||
end
|
||||
Loading…
Reference in a new issue