cinch-logger-canonical 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cinch-logger-canonical.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brian Haberer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Cinch::Logger::Canonical
2
+
3
+ This Logger will log the channels that the bot joins in a very simple format:
4
+
5
+ [YYYY-MM-DD HH:MM:SS] <NICK> MESSAGE
6
+ [YYYY-MM-DD HH:MM:SS] * NICK ACTION
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'cinch-logger-canonical'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install cinch-logger-canonical
21
+
22
+ ## Usage
23
+
24
+ All you need to do is add the new logger to your @bot:
25
+
26
+ @bot.loggers << Cinch::Logger::CanonicalLogger.new(channel, @bot)
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cinch-logger-canonical/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "cinch-logger-canonical"
8
+ gem.version = Cinch::Logger::Canonical::VERSION
9
+ gem.authors = ["Brian Haberer"]
10
+ gem.email = ["bhaberer@gmail.com"]
11
+ gem.description = %q{Cinch logger that logs basic irc channel chatter}
12
+ gem.summary = %q{Simple Cinch Logger}
13
+ gem.homepage = "https://github.com/bhaberer/cinch-logger-canonical"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,73 @@
1
+ require "cinch-logger-canonical/version"
2
+ require "cinch/logger"
3
+
4
+ module Cinch
5
+ class Logger
6
+ class CanonicalLogger < Cinch::Logger
7
+ # (see Logger#log)
8
+ def log(messages, event = :debug, level = event)
9
+ return unless will_log?(level)
10
+
11
+ @mutex.synchronize do
12
+ # Ensure that we're logging to the right file.
13
+ Array(messages).each do |message|
14
+ next unless message.match(Regexp.new("PRIVMSG ##{@channel}"))
15
+ message = format_general(message)
16
+ message = format_message(message, event)
17
+
18
+ next if message.nil?
19
+ sync_logfile
20
+ @output.puts message.encode("locale", {:invalid => :replace, :undef => :replace})
21
+ end
22
+ end
23
+ end
24
+
25
+ def initialize(channel, bot)
26
+ @bot_name = bot.nick
27
+ @channel = channel
28
+ @output = File.open(today_log, 'a')
29
+ @output.sync = true
30
+ @mutex = Mutex.new
31
+ @level = :debug
32
+ end
33
+
34
+ private
35
+
36
+ def today_log
37
+ # TODO allow for custom log paths
38
+ Dir.mkdir('./logs') unless Dir.exist?('./logs')
39
+ File.join('.', 'logs', "#{@channel}_#{Time.now.strftime("%Y-%m-%d")}.log")
40
+ end
41
+
42
+ def format_incoming(message)
43
+ nick = message.match(/^:(\S+)!/)[1] rescue 'NONICK'
44
+ msg = message.match(/#\S+ :(.+)$/)[1] rescue 'NOMSG'
45
+ generic_format(nick, msg)
46
+ end
47
+
48
+ def format_outgoing(message)
49
+ msg = message.match(/#\S+ :(.+)$/)[1] rescue 'NOMSG'
50
+ generic_format(@bot_name, msg)
51
+ end
52
+
53
+ def generic_format(nick, m)
54
+ message = '[' + Time.now.strftime("%Y-%m-%d %H:%M:%S") + '] '
55
+ # This seems gross, fix this with better rubies.
56
+ if m.codepoints.first == 1 && m.match(/ACTION/)
57
+ message << " * #{nick} #{m.gsub(/^.?ACTION /, '')}"
58
+ else
59
+ message << "<#{nick}> #{m}"
60
+ end
61
+ return message
62
+ end
63
+
64
+ def sync_logfile
65
+ unless @output.path == today_log
66
+ @output.close
67
+ @output = File.open(today_log, 'a')
68
+ @output.sync = true
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,7 @@
1
+ module Cinch
2
+ class Logger
3
+ module Canonical
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-logger-canonical
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian Haberer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-19 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Cinch logger that logs basic irc channel chatter
15
+ email:
16
+ - bhaberer@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - cinch-logger-canonical.gemspec
27
+ - lib/cinch-logger-canonical.rb
28
+ - lib/cinch-logger-canonical/version.rb
29
+ homepage: https://github.com/bhaberer/cinch-logger-canonical
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Simple Cinch Logger
53
+ test_files: []