Last active
July 15, 2019 23:08
-
-
Save plusjade/5646375 to your computer and use it in GitHub Desktop.
Custom rails logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# place in ./config/initializers | |
# Usage | |
# LL.warn "blah" | |
# LL.warn @profile.inspect | |
require 'pp' | |
require 'log4r' | |
require 'log4r/configurator' | |
require 'log4r/yamlconfigurator' | |
require 'log4r/outputter/fileoutputter' | |
require 'log4r/outputter/datefileoutputter' | |
require 'log4r/outputter/emailoutputter' | |
include Log4r | |
# Custom debug logging | |
LL = Log4r::Logger.new("ll") | |
LL.add Log4r::FileOutputter.new 'll', { | |
filename: 'log/ll.log', | |
formatter: Log4r::PatternFormatter.new(:pattern => "%M"), | |
trunc: true | |
} | |
LL.info "LL is ready to log." | |
ActionController::Base.send(:before_filter, Proc.new { | |
LL.info {"\n\n\n\e[35m#{Time.now.to_default_s}\e[0m\t"} | |
LL.info { | |
path = request.filtered_path | |
message = "Started #{request.request_method} \"#{path}\" for #{request.ip} at #{Time.now.to_default_s}\n" | |
} | |
Log4r::Logger["mongoid-log"].info {"\n\n\n\e[35m#{Time.now.to_default_s}\e[0m\t"} | |
Log4r::Logger["mongoid-log"].info { | |
path = request.filtered_path | |
message = "Started #{request.request_method} \"#{path}\" for #{request.ip} at #{Time.now.to_default_s}\n" | |
} | |
}) | |
Rails.application.config.before_configuration do | |
# Base logging | |
Rails.application.config.log_level = :debug | |
Rails.application.config.logger = Log4r::Logger.new("App-log") | |
Rails.application.config.logger.add Log4r::Outputter.stdout | |
# MONGO LOGGING | |
mongoid_logger = Log4r::Logger.new("mongoid-log") | |
mongoid_logger.add Log4r::FileOutputter.new 'mongoid-log', { | |
filename: 'log/mongoid.log', | |
formatter: Log4r::PatternFormatter.new(:pattern => "%m"), | |
trunc: true | |
} | |
Mongoid.logger = mongoid_logger | |
Moped.logger = mongoid_logger | |
#Rails.application.config.mongoid.persist_in_safe_mode = true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment