Commit ac96232d authored by Benjamin Neff's avatar Benjamin Neff Committed by Dennis Schubert

use logging gem for better logging with class name and log-level

parent 49f0fb6d
......@@ -169,6 +169,10 @@ gem "mobile-fu", "1.3.1"
gem "will_paginate", "3.0.7"
gem "rails-timeago", "2.11.0"
# Logging
gem "logging-rails", "0.5.0", require: "logging/rails"
# Workarounds
# https://github.com/rubyzip/rubyzip#important-note
gem "zip-zip"
......
......@@ -390,6 +390,12 @@ GEM
celluloid (~> 0.16.0)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
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)
lumberjack (1.0.9)
......@@ -767,6 +773,7 @@ DEPENDENCIES
js_image_paths (= 0.0.2)
jshintrb (= 0.3.0)
json (= 1.8.2)
logging-rails (= 0.5.0)
markerb (= 1.0.2)
messagebus_ruby_api (= 1.0.3)
mini_magick (= 4.2.3)
......
......@@ -31,4 +31,10 @@ Diaspora::Application.configure do
# Expands the lines which load the assets
config.assets.debug = true
# Set the logging destination(s)
config.log_to = %w[stdout file]
# Show the logging configuration on STDOUT
config.show_log_configuration = true
end
......@@ -37,6 +37,12 @@ Diaspora::Application.configure do
# Log level
config.log_level = :info
# 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 ]
......@@ -66,7 +72,7 @@ Diaspora::Application.configure do
config.active_support.deprecation = :notify
# For nginx:
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
config.action_dispatch.x_sendfile_header = "X-Accel-Redirect"
if AppConfig.environment.assets.host.present?
config.action_controller.asset_host = AppConfig.environment.assets.host.get
......
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.
layout = Logging.layouts.pattern(pattern: "[%d] %-5l %c : %m\n")
# 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: "[%d] %-5l %c : %m\n",
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.level = config.log_level
Logging.logger.root.appenders = config.log_to unless config.log_to.empty?
# Under Phusion Passenger smart spawning, we need to reopen all IO streams
# after workers have forked.
#
# The rolling file appender uses shared file locks to ensure that only one
# process will roll the log file. Each process writing to the file must have
# its own open file descriptor for `flock` to function properly. Reopening
# the file descriptors after forking ensures that each worker has a unique
# file descriptor.
if defined? PhusionPassenger
PhusionPassenger.on_event(:starting_worker_process) do |forked|
Logging.reopen if forked
end
end
end
......@@ -26,6 +26,8 @@ before_fork do |_server, _worker|
end
after_fork do |_server, _worker|
Logging.reopen # reopen logfiles to obtain a new file descriptor
ActiveRecord::Base.establish_connection # preloading app in master, so reconnect to DB
# We don't generate uuids in the frontend, but let's be on the safe side
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment