修改日志分割关闭
This commit is contained in:
parent
922958e732
commit
343e9d9434
|
@ -17,7 +17,7 @@ RedmineApp::Application.configure do
|
||||||
# config.logger.level = Logger::INFO
|
# config.logger.level = Logger::INFO
|
||||||
|
|
||||||
# Full error reports are disabled and caching is turned on
|
# Full error reports are disabled and caching is turned on
|
||||||
config.logger = Logger.new('log/production.log', 'daily',1048576) # daily, weekly or monthly
|
# config.logger = Logger.new('log/production.log', 'daily',1048576) # daily, weekly or monthly
|
||||||
config.action_controller.perform_caching = true
|
config.action_controller.perform_caching = true
|
||||||
|
|
||||||
# to additional_environment.rb
|
# to additional_environment.rb
|
||||||
|
|
|
@ -194,36 +194,36 @@ require 'fileutils'
|
||||||
# end
|
# end
|
||||||
# # e.g. "Thu Sep 22 08:51:08 GMT+9:00 2005: hello world"
|
# # e.g. "Thu Sep 22 08:51:08 GMT+9:00 2005: hello world"
|
||||||
#
|
#
|
||||||
class Logger
|
# class Logger
|
||||||
#具体内容请看https://bugs.ruby-lang.org/issues/7303
|
# #具体内容请看https://bugs.ruby-lang.org/issues/7303
|
||||||
# Device used for logging messages.
|
# # Device used for logging messages.
|
||||||
class LogDevice
|
# class LogDevice
|
||||||
def shift_log_period(period_end)
|
# def shift_log_period(period_end)
|
||||||
postfix = period_end.strftime("%Y%m%d") # YYYYMMDD
|
# postfix = period_end.strftime("%Y%m%d") # YYYYMMDD
|
||||||
age_file = "#{@filename}.#{postfix}"
|
# age_file = "#{@filename}.#{postfix}"
|
||||||
if FileTest.exist?(age_file)
|
# if FileTest.exist?(age_file)
|
||||||
# try to avoid filename crash caused by Timestamp change.
|
# # try to avoid filename crash caused by Timestamp change.
|
||||||
idx = 0
|
# idx = 0
|
||||||
# .99 can be overridden; avoid too much file search with 'loop do'
|
# # .99 can be overridden; avoid too much file search with 'loop do'
|
||||||
while idx < 100
|
# while idx < 100
|
||||||
idx += 1
|
# idx += 1
|
||||||
age_file = "#{@filename}.#{postfix}.#{idx}"
|
# age_file = "#{@filename}.#{postfix}.#{idx}"
|
||||||
break unless FileTest.exist?(age_file)
|
# break unless FileTest.exist?(age_file)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
# @dev.close rescue nil
|
# # @dev.close rescue nil
|
||||||
# File.rename("#{@filename}", age_file)
|
# # File.rename("#{@filename}", age_file)
|
||||||
# @dev = create_logfile(@filename)
|
# # @dev = create_logfile(@filename)
|
||||||
#覆盖原来lib库的方法,将上边三行删除,增加下边两行
|
# #覆盖原来lib库的方法,将上边三行删除,增加下边两行
|
||||||
FileUtils.cp(@filename, age_file)
|
# FileUtils.cp(@filename, age_file)
|
||||||
reset_logfile(@dev) # see below for this new method return true
|
# reset_logfile(@dev) # see below for this new method return true
|
||||||
return true
|
# return true
|
||||||
end
|
# end
|
||||||
#打开原来lib库,新增一个方法
|
# #打开原来lib库,新增一个方法
|
||||||
def reset_logfile(logdev)
|
# def reset_logfile(logdev)
|
||||||
logdev.truncate( 0 )
|
# logdev.truncate( 0 )
|
||||||
logdev.sync = true
|
# logdev.sync = true
|
||||||
add_log_header(logdev)
|
# add_log_header(logdev)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
Loading…
Reference in New Issue