summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/core/irclog.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/rbot/core/irclog.rb b/lib/rbot/core/irclog.rb
index 39d0a1fb..e091832d 100644
--- a/lib/rbot/core/irclog.rb
+++ b/lib/rbot/core/irclog.rb
@@ -20,6 +20,9 @@ class IrcLogModule < CoreBotModule
bot.plugins.delegate 'event_irclog_list_changed', bot.config['irclog.no_log'], v
},
:desc => "List of channels and nicks for which logging is enabled. IRC patterns can be used too. This can be used to override wide patters in irclog.no_log")
+ Config.register Config::StringValue.new('irclog.filename_format',
+ :default => '%{where}', :requires_rescan => true,
+ :desc => "filename pattern for the IRC log. You can put typical strftime keys such as %Y for year and %m for month, plus the special %{where} key for location (channel name or user nick)")
attr :nolog_rx, :dolog_rx
def initialize
@@ -29,6 +32,7 @@ class IrcLogModule < CoreBotModule
@logs = Hash.new
Dir.mkdir("#{@bot.botclass}/logs") unless File.exist?("#{@bot.botclass}/logs")
event_irclog_list_changed(@bot.config['irclog.no_log'], @bot.config['irclog.do_log'])
+ @fn_format = @bot.config['irclog.filename_format']
end
def can_log_on(where)
@@ -232,6 +236,10 @@ class IrcLogModule < CoreBotModule
irclog m.logmessage, ".unknown"
end
+ def logfilepath(where_str, now)
+ File.join(@bot.botclass, 'logs', now.strftime(@fn_format) % { :where => where_str })
+ end
+
protected
def loggers_thread
ls = nil
@@ -247,6 +255,14 @@ class IrcLogModule < CoreBotModule
where_str = where.downcase.gsub(/[:!?$*()\/\\<>|"']/, "_")
end
return unless can_log_on(where_str)
+
+ # close the previous logfile if we're rotating
+ if @logs.has_key? where_str
+ fp = logfilepath(where_str, now)
+ logfile_close(where_str, 'log rotation') if fp != @logs[where_str][1].path
+ end
+
+ # (re)open the logfile if necessary
unless @logs.has_key? where_str
if @logs.size > @bot.config['irclog.max_open_files']
@logs.keys.sort do |a, b|
@@ -255,7 +271,9 @@ class IrcLogModule < CoreBotModule
logfile_close w, "idle since #{@logs[w][0]}"
end
end
- f = File.new("#{@bot.botclass}/logs/#{where_str}", "a")
+ fp = logfilepath(where_str, now)
+ FileUtils.mkdir_p File.dirname(fp)
+ f = File.new(fp, "a")
f.sync = true
f.puts "[#{stamp}] @ Log started by #{@bot.myself.nick}"
@logs[where_str] = [now, f]