Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 quick fixes about doc and params validate #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/log4r/outputter/datefileoutputter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
# == Usage
#
# df_out = DateFileOutputter.new('name',
# :dirname="/tmp", :date_pattern=>"%m-%d"
# :dirname=>"/tmp", :date_pattern=>"%m-%d"
# )
#
# == Rate of Change
#
# A new logfile is created whenever the current time as formatted by the date
# pattern no longer matches the previous time. (This is a simple String
# pattern no longer matches the previous time. (This is a simple String
# comparison.) So, in order to change the frequency of the rollover, just
# alter the date pattern to match how fast the files should be generated.
# alter the date pattern to match how fast the files should be generated.
# For instance, to generate files by the minute,
#
# df_out.date_pattern = "%M"
Expand All @@ -40,6 +40,12 @@ module Log4r
#
# [<tt>:dirname</tt>] Directory of the log file
# [<tt>:date_pattern</tt>] Time.strftime format string (default is "%Y-%m-%d")
# Format directives: (details see: http://apidock.com/ruby/Time/strftime)
# %Y - Year
# %m - Month of the year
# %d - Day of the month
# %H - Hour of the day
# %M - Minute of the hour

class DateFileOutputter < FileOutputter
DEFAULT_DATE_FMT = "%Y-%m-%d"
Expand All @@ -57,6 +63,13 @@ def initialize(_name, hash={})
end

_filename = (hash[:filename] or hash['filename'])
# :filename only work with format like xx.xx, should have validate
if _filename
if not /\w+\.\w+/.match(_filename)
raise StandardError, "'#{_filename}' must be with format like xx.xx", caller
end
end

if _filename.nil?
@filebase = File.basename( $0, '.rb') + ".log"
else
Expand Down Expand Up @@ -97,7 +110,7 @@ def requiresChange
false
end

# change the file
# change the file
def change
begin
@out.close
Expand Down