From 5824f70fe34dcc618b053458c3cec96a4fbea87c Mon Sep 17 00:00:00 2001 From: linhk <304431313@.com> Date: Wed, 17 Sep 2014 13:54:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=97=A5=E5=BF=97=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/logger_helper.rb | 27 +++++++++++++++++++++++++++ config/environment.rb | 13 +++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 app/helpers/logger_helper.rb 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 + +