输出日志代码

This commit is contained in:
linhk 2014-09-17 13:54:55 +08:00
parent 7c97c0391b
commit 5824f70fe3
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,27 @@
module LoggerHelper
#输出日志
def OutLogger
#日志输出级别
#Rails.logger.level = Logger::INFO
if(!File.exist?("database"))
Dir.mkdir("database")
end
if(!File.exist?("database/get"))
Dir.mkdir("database/get")
end
if(!File.exist?("database/sql"))
Dir.mkdir("database/sql")
end
if(!File.exist?("database/controller"))
Dir.mkdir("database/controller")
end
Rails.logger = Logger.new("database/get/#{Date.today.to_s}.log", "daily")
ActiveRecord::Base.logger = Logger.new("database/sql/#{Date.today.to_s}.log", "daily")
ActionController::Base.logger = Logger.new("database/controller/#{Date.today.to_s}.log", "daily")
end
end

View File

@ -13,3 +13,16 @@ end
# Initialize the rails application
RedmineApp::Application.initialize!
#日志格式
class Logger
def format_message(level, time, progname, msg)
"#{time.to_s(:db)} #{level} -- #{msg}\r\n"
end
end
#输出日志(database文件夹下get、sql、controller按照日期 分别输出路由信息、SQL语句、调用页面)[影响系统效率使用完请注释掉]
#include LoggerHelper
#LoggerHelper.OutLogger