padrino_gelflogger 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PadrinoGelflogger
2
2
 
3
- TODO: Write a gem description
3
+ This gem allows logging to [Graylog](http://graylog2.org/) via [Padrino](padrinorb.com).
4
4
 
5
5
  ## Installation
6
6
 
@@ -17,8 +17,16 @@ Or install it yourself as:
17
17
  $ gem install padrino_gelflogger
18
18
 
19
19
  ## Usage
20
+ In your config/boot.rb add something like this:
20
21
 
21
- TODO: Write usage instructions here
22
+ Padrino.after_load do
23
+ if %w[acceptance production].include? PADRINO_ENV
24
+ Padrino.logger = Padrino::GelfLogger.new("graylog-server", 12201, 'wan', :facility => 'AppName', :level => :devel)
25
+ end
26
+ end
27
+
28
+
29
+ More information about the parameters can be found at in the [http://rubydoc.info/github/Graylog2/gelf-rb/master/GELF/Notifier](Graylog2) gem docs.
22
30
 
23
31
  ## Contributing
24
32
 
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
3
+ require 'bundler/setup'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.pattern = "spec/*_spec.rb"
8
+ t.libs << "spec"
9
+ t.verbose = true
10
+ end
@@ -0,0 +1,56 @@
1
+ module Padrino
2
+ class GelfLogger < GELF::Notifier
3
+ attr_accessor :level
4
+
5
+ LevelMappings = {
6
+ fatal: 4,
7
+ error: 3,
8
+ warn: 2,
9
+ info: 1,
10
+ debug: 0,
11
+ devel: 0
12
+ }
13
+
14
+ Padrino::Logger::Levels.each_pair do |name, number|
15
+ define_method(name) do |*args|
16
+ if args.size > 1
17
+ bench(*args)
18
+ else
19
+ push(args * '', name)
20
+ end
21
+ end
22
+ end
23
+
24
+ def log(*args)
25
+ end
26
+
27
+ def log_static(*args)
28
+ end
29
+
30
+ def push(message = nil, level = nil)
31
+ msg = clean(message.to_s.strip)
32
+ return if message.empty?
33
+ notify_with_level(gelf_level(level), msg)
34
+ end
35
+
36
+ def bench(action, began_at, message, level=:debug, color=:yellow)
37
+ duration = Time.now - began_at
38
+ short_message = "%s %0.4fms: %s" % [ action, duration, clean(message.to_s) ]
39
+ notify_with_level(gelf_level(level), short_message: short_message, _duration: duration, _action: action)
40
+ end
41
+
42
+ private
43
+ def clean(message)
44
+ message = message.to_s.dup
45
+ message.strip!
46
+ message.gsub!(/\e\[[^m]*m/, '') # remove useless ansi color codes
47
+ return message
48
+ end
49
+
50
+ def gelf_level(level=nil)
51
+ level = :debug if level.nil?
52
+ LevelMappings[level] || 0
53
+ end
54
+
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module PadrinoGelflogger
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,5 +1,4 @@
1
- require "padrino_gelflogger/version"
2
-
3
- module PadrinoGelflogger
4
- # Your code goes here...
5
- end
1
+ require 'padrino_gelflogger/version'
2
+ require 'gelf'
3
+ require 'padrino-core/logger'
4
+ require 'padrino_gelflogger/gelf_logger'
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["pz@anixe.pl"]
7
7
  gem.description = %q{Log from Padrino to Graylog2}
8
8
  gem.summary = %q{uses GELF.}
9
- gem.homepage = ""
9
+ gem.homepage = "http://github.com/pzol/padrino_gelflogger"
10
10
 
11
11
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
12
  gem.files = `git ls-files`.split("\n")
@@ -14,4 +14,13 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "padrino_gelflogger"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = PadrinoGelflogger::VERSION
17
+ gem.add_dependency 'gelf', '>=1.3.2'
18
+ gem.add_dependency 'padrino-core', '>=0.10.5'
19
+
20
+ gem.add_development_dependency 'minitest', '>=2.10.0'
21
+ gem.add_development_dependency 'minitest-reporters'
22
+ gem.add_development_dependency 'rr'
23
+ gem.add_development_dependency 'timecop'
24
+ gem.add_development_dependency 'rake'
25
+
17
26
  end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Padrino::GelfLogger do
4
+ include RR::Adapters::MiniTest
5
+ padrino_levels = [:fatal, :error, :warn, :info, :debug, :devel]
6
+
7
+ before do
8
+ @logger = Padrino::GelfLogger.new('0.0.0.0', 12201, 'WAN', :facility => 'Padrino::GelfLogger', :level => GELF::DEBUG)
9
+ end
10
+
11
+ it "#fatal" do
12
+ mock(@logger).notify_with_level(4, "test")
13
+ @logger.fatal "test"
14
+ end
15
+
16
+ it "#error" do
17
+ mock(@logger).notify_with_level(3, "test")
18
+ @logger.error "test"
19
+ end
20
+
21
+ it "#warn" do
22
+ mock(@logger).notify_with_level(2, "test")
23
+ @logger.warn "test"
24
+ end
25
+
26
+ it "#info" do
27
+ mock(@logger).notify_with_level(1, "test")
28
+ @logger.info "test"
29
+ end
30
+
31
+ it "#debug" do
32
+ mock(@logger).notify_with_level(0, "test")
33
+ @logger.debug "test"
34
+ end
35
+
36
+ it "#devel" do
37
+ mock(@logger).notify_with_level(0, "test")
38
+ @logger.devel "test"
39
+ end
40
+
41
+ it '#bench' do
42
+ mock(@logger).notify_with_level(0, {short_message: 'action 20.0000ms: message', _duration: 20.0, _action: 'action'})
43
+ Timecop.freeze(Time.local(2012, 12, 20, 20, 12, 20)) do
44
+ @logger.bench("action", Time.local(2012, 12, 20, 20, 12, 00), "message", level=:debug, color=:yellow)
45
+ end
46
+ end
47
+
48
+ it 'should respond to #log_static for sinatra and not log anything' do
49
+ assert_respond_to @logger, :log_static
50
+ end
51
+
52
+ it 'should respond to #log and not log anything' do
53
+ assert_respond_to @logger, :log
54
+ end
55
+
56
+ end
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require File.expand_path '../../lib/padrino_gelflogger', __FILE__
5
+
6
+ require 'minitest/autorun'
7
+ require 'minitest/unit'
8
+ require 'minitest/spec'
9
+ require 'timecop'
10
+
11
+ require 'rr'
12
+
13
+
14
+
15
+ class MockSpec < MiniTest::Spec
16
+ include RR::Adapters::RRMethods
17
+ end
18
+ MiniTest::Spec.register_spec_type(/.*/, MockSpec)
19
+
20
+ require 'minitest/reporters'
21
+ MiniTest::Unit.runner = MiniTest::SuiteRunner.new
22
+ MiniTest::Unit.runner.reporters << MiniTest::Reporters::SpecReporter.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino_gelflogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,84 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-01-18 00:00:00.000000000Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gelf
16
+ requirement: &70175824024040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70175824024040
25
+ - !ruby/object:Gem::Dependency
26
+ name: padrino-core
27
+ requirement: &70175824023340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.10.5
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70175824023340
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70175824022480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 2.10.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70175824022480
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest-reporters
49
+ requirement: &70175824021980 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70175824021980
58
+ - !ruby/object:Gem::Dependency
59
+ name: rr
60
+ requirement: &70175824021280 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70175824021280
69
+ - !ruby/object:Gem::Dependency
70
+ name: timecop
71
+ requirement: &70175824020520 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70175824020520
80
+ - !ruby/object:Gem::Dependency
81
+ name: rake
82
+ requirement: &70175824019660 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70175824019660
14
91
  description: Log from Padrino to Graylog2
15
92
  email:
16
93
  - pz@anixe.pl
@@ -24,9 +101,12 @@ files:
24
101
  - README.md
25
102
  - Rakefile
26
103
  - lib/padrino_gelflogger.rb
104
+ - lib/padrino_gelflogger/gelf_logger.rb
27
105
  - lib/padrino_gelflogger/version.rb
28
106
  - padrino_gelflogger.gemspec
29
- homepage: ''
107
+ - spec/gelf_logger_spec.rb
108
+ - spec/spec_helper.rb
109
+ homepage: http://github.com/pzol/padrino_gelflogger
30
110
  licenses: []
31
111
  post_install_message:
32
112
  rdoc_options: []
@@ -38,16 +118,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
38
118
  - - ! '>='
39
119
  - !ruby/object:Gem::Version
40
120
  version: '0'
121
+ segments:
122
+ - 0
123
+ hash: -3409828036910420846
41
124
  required_rubygems_version: !ruby/object:Gem::Requirement
42
125
  none: false
43
126
  requirements:
44
127
  - - ! '>='
45
128
  - !ruby/object:Gem::Version
46
129
  version: '0'
130
+ segments:
131
+ - 0
132
+ hash: -3409828036910420846
47
133
  requirements: []
48
134
  rubyforge_project:
49
135
  rubygems_version: 1.8.6
50
136
  signing_key:
51
137
  specification_version: 3
52
138
  summary: uses GELF.
53
- test_files: []
139
+ test_files:
140
+ - spec/gelf_logger_spec.rb
141
+ - spec/spec_helper.rb