diff --git a/app/helpers/logger_helper.rb b/app/helpers/logger_helper.rb new file mode 100644 index 000000000..af04e38d3 --- /dev/null +++ b/app/helpers/logger_helper.rb @@ -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 + diff --git a/config/environment.rb b/config/environment.rb index f44e25ae3..b105e8e25 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -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 + +