loggem 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/loggem/event.rb +49 -0
- data/lib/loggem/extensions/active_record.rb +25 -0
- data/lib/loggem/extensions/sequel.rb +23 -0
- data/lib/loggem/formatters/json.rb +13 -0
- data/lib/loggem/formatters/key_value.rb +32 -0
- data/lib/loggem/formatters/raw.rb +11 -0
- data/lib/loggem/logger.rb +60 -0
- data/lib/loggem/railtie.rb +14 -0
- data/lib/loggem/version.rb +3 -0
- data/lib/loggem.rb +30 -0
- data/loggem.gemspec +24 -0
- data/spec/loggem/event_spec.rb +76 -0
- data/spec/loggem/formatters/json_spec.rb +12 -0
- data/spec/loggem/formatters/key_value_spec.rb +18 -0
- data/spec/loggem/formatters/raw_spec.rb +10 -0
- data/spec/loggem/logger_spec.rb +102 -0
- data/spec/loggem_spec.rb +31 -0
- data/spec/spec_helper.rb +3 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f4ccc993806cfff7d3136dda26cb18c894841ba
|
4
|
+
data.tar.gz: 91e20794192eef5747113598247b5fc3561ff012
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3fcbffff07692ebbac951698b5566eb87d158878e6ea5d73127755e2b33484efb1bfec6ff4c986abea8b81b61c9e99fc6410751cb18abe477ebbe43f1c837694
|
7
|
+
data.tar.gz: 728493834434c189190ed48d5609160b1672f5dace4db4ecf4327b2c55b78d8f8b09dccd43c8d62eb6b6eef6a833cdf2f5bb81e8cc90f181da56854c752a90db
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Istvan Demeter
|
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,29 @@
|
|
1
|
+
# Loggem
|
2
|
+
|
3
|
+
Simple log wrapper with different formatters. Minimal Rails/ActiveRecord/Sequel support, so far
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'loggem'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install loggem
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/qw3r/loggem/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/loggem/event.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Loggem
|
2
|
+
class Event
|
3
|
+
|
4
|
+
def initialize(arguments = {})
|
5
|
+
@data = {}
|
6
|
+
@arguments = arguments
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
def data
|
12
|
+
parse_arguments @arguments
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
STACKTRACE_SIZE = 5
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
def parse_arguments(arguments)
|
24
|
+
@data.merge! at: arguments.fetch(:level)
|
25
|
+
@data.merge! parse arguments.fetch(:message)
|
26
|
+
@data.merge! parse arguments.fetch(:payload, {})
|
27
|
+
@data.merge! arguments.fetch(:context, {})
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
def parse(object)
|
33
|
+
case object
|
34
|
+
when Exception
|
35
|
+
return {message: object.message} if object.backtrace.nil?
|
36
|
+
|
37
|
+
{message: object.message, stacktrace: object.backtrace[0..(STACKTRACE_SIZE - 1)].join("\n")}
|
38
|
+
|
39
|
+
when Hash
|
40
|
+
object
|
41
|
+
|
42
|
+
else
|
43
|
+
{message: object.to_s.strip}
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Loggem
|
4
|
+
module Extensions
|
5
|
+
module ActiveRecord
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
klass.send :remove_method, :sql
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def sql(event)
|
14
|
+
payload = event.payload
|
15
|
+
return if %w(SCHEMA EXPLAIN).include?(payload[:name])
|
16
|
+
|
17
|
+
debug message: payload[:sql], duration: event.duration.round(4), description: payload[:name], source: 'active_record'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
::ActiveRecord::LogSubscriber.send :include, ActiveRecord
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
|
3
|
+
module Loggem
|
4
|
+
module Extensions
|
5
|
+
module Sequel
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
klass.send :remove_method, :log_duration
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def log_duration(duration, message)
|
14
|
+
return if message.start_with? 'SET '
|
15
|
+
|
16
|
+
log_each((lwd = log_warn_duration and duration >= lwd) ? :warn : sql_log_level, {message: message, duration: (duration * 1000).round(4), source: 'sequel'})
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
::Sequel::Database.send :include, Sequel
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Loggem
|
2
|
+
module Formatters
|
3
|
+
class KeyValue
|
4
|
+
|
5
|
+
def call(data)
|
6
|
+
data.each.map { |k, v| format k, v }.join ' '
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def format(key, value)
|
14
|
+
%Q|#{key}="#{format_value value}"|
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
def format_value(value)
|
20
|
+
case value
|
21
|
+
when String
|
22
|
+
value.gsub('"') { %q|\"| }
|
23
|
+
when Symbol
|
24
|
+
value
|
25
|
+
else
|
26
|
+
value.inspect
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Loggem
|
4
|
+
class Logger
|
5
|
+
|
6
|
+
attr_reader :context
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
def initialize(logger = ::Logger.new(STDOUT))
|
11
|
+
@logger = logger
|
12
|
+
@context = {}
|
13
|
+
@formatter = ::Loggem::Formatters::Json.new
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
def formatter=(formatter)
|
19
|
+
raise ArgumentError.new("Formatter must respond to 'call'") unless formatter.respond_to?(:call)
|
20
|
+
|
21
|
+
@formatter = formatter
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
[:debug, :info, :warn, :error, :fatal].each do |level|
|
27
|
+
define_method level do |message, payload = {}|
|
28
|
+
log level, message, payload
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
def method_missing(method, *arguments)
|
35
|
+
logger.public_send method, *arguments
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
attr_reader :logger, :formatter
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
def log(level, message, payload)
|
47
|
+
logger.public_send level, formatter.call(build_event(level, message, payload))
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
def build_event(level, message, payload)
|
53
|
+
::Loggem::Event.new(level: level,
|
54
|
+
message: message,
|
55
|
+
payload: payload,
|
56
|
+
context: context).data
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
#require 'action_view/log_subscriber'
|
3
|
+
#require 'action_controller/log_subscriber'
|
4
|
+
|
5
|
+
module Lograge
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
config.loggem = ActiveSupport::OrderedOptions.new
|
8
|
+
config.loggem.enabled = false
|
9
|
+
|
10
|
+
initializer :loggem do |app|
|
11
|
+
::Loggem.setup_rails app if config.loggem.enabled
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/loggem.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'loggem/version'
|
2
|
+
require 'loggem/logger'
|
3
|
+
require 'loggem/event'
|
4
|
+
|
5
|
+
require 'loggem/formatters/raw'
|
6
|
+
require 'loggem/formatters/json'
|
7
|
+
require 'loggem/formatters/key_value'
|
8
|
+
|
9
|
+
|
10
|
+
module Loggem
|
11
|
+
|
12
|
+
def self.setup_rails(app)
|
13
|
+
config = app.config.loggem
|
14
|
+
|
15
|
+
logger = Loggem::Logger.new config.logger
|
16
|
+
logger.formatter = config.formatter || ::Loggem::Formatters::Json.new
|
17
|
+
logger.context.merge!(config.context || {})
|
18
|
+
(config.extensions || []).each { |ext| load_extension ext }
|
19
|
+
|
20
|
+
::Rails.logger = app.config.logger = logger
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def self.load_extension(extension)
|
25
|
+
require "loggem/extensions/#{extension}"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'loggem/railtie' if defined?(Rails)
|
data/loggem.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'loggem/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "loggem"
|
8
|
+
spec.version = Loggem::VERSION
|
9
|
+
spec.authors = ["Istvan Demeter"]
|
10
|
+
spec.email = ["istvan.demeter@emarsys.com"]
|
11
|
+
spec.summary = %q{Simple log wrapper with different formatters. Rails/ActiveRecord/Sequel support, so far}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/qw3r/loggem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Loggem::Event do
|
4
|
+
subject { Loggem::Event }
|
5
|
+
|
6
|
+
describe 'parsing strings' do
|
7
|
+
it 'should return the parsed message' do
|
8
|
+
event = subject.new level: :info, message: 'string'
|
9
|
+
|
10
|
+
expect(event.data).to eq(at: :info, message: 'string')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should strip the leading and trailing spaces' do
|
14
|
+
event = subject.new level: :info, message: ' string '
|
15
|
+
|
16
|
+
expect(event.data).to eq(at: :info, message: 'string')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe 'parsing exceptions' do
|
22
|
+
let(:exception) { StandardError.new 'error message' }
|
23
|
+
|
24
|
+
it 'should handle exceptions with no stacktrace' do
|
25
|
+
event = subject.new level: :info, message: exception
|
26
|
+
|
27
|
+
expect(event.data).to eq(at: :info, message: 'error message')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should log the stacktrace of exceptions (up to 5 lines)' do
|
31
|
+
exception.set_backtrace Array.new(8) { |i| "line#{i}" }
|
32
|
+
|
33
|
+
event = subject.new level: :info, message: exception
|
34
|
+
|
35
|
+
expect(event.data).to eq(at: :info, message: 'error message', stacktrace: "line0\nline1\nline2\nline3\nline4")
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
describe 'logging arbitrary objects' do
|
42
|
+
it 'should not fail' do
|
43
|
+
event = subject.new level: :info, message: Object.new
|
44
|
+
|
45
|
+
|
46
|
+
expect { event.data }.to_not raise_error
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
describe 'logging Hash' do
|
52
|
+
it 'should pass it as-is' do
|
53
|
+
event = subject.new level: :info, message: {foo: 'bar'}
|
54
|
+
|
55
|
+
expect(event.data).to eq(at: :info, foo: 'bar')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
describe 'logging extra information' do
|
61
|
+
it 'should add any extra information given in a Hash without changes' do
|
62
|
+
event = subject.new level: :info, message: 'sh!t happen', payload: {customer: 123}
|
63
|
+
|
64
|
+
expect(event.data).to eq(at: :info, message: 'sh!t happen', customer: 123)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
describe 'logging context information' do
|
70
|
+
it "should log the context in every log message" do
|
71
|
+
event = subject.new level: :info, message: 'sh!t happen', context: {request_id: 123}
|
72
|
+
|
73
|
+
expect(event.data).to eq(at: :info, message: 'sh!t happen', request_id: 123)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Loggem::Formatters::Json do
|
4
|
+
|
5
|
+
describe "#call" do
|
6
|
+
it "returns the JSON encoded data" do
|
7
|
+
allow(JSON).to receive(:dump).with('raw-data').and_return 'json-data'
|
8
|
+
|
9
|
+
expect(subject.call 'raw-data').to eq 'json-data'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Loggem::Formatters::KeyValue do
|
4
|
+
|
5
|
+
describe "#call" do
|
6
|
+
{
|
7
|
+
{message: 'event worth to mention'} => %q{message="event worth to mention"},
|
8
|
+
{message: "single ' quote"} => %q{message="single ' quote"},
|
9
|
+
{message: "double \" quote"} => %q{message="double \" quote"},
|
10
|
+
{tags: %w[a b c]} => %q{tags="["a", "b", "c"]"},
|
11
|
+
{symbol: :symbol} => %q{symbol="symbol"},
|
12
|
+
}.each do |input, output|
|
13
|
+
it "returns the data as key-value pairs" do
|
14
|
+
expect(subject.call input).to eq output
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Loggem::Logger do
|
4
|
+
let(:logger) { double 'Logger' }
|
5
|
+
|
6
|
+
subject { Loggem::Logger.new logger }
|
7
|
+
|
8
|
+
describe "use formatters" do
|
9
|
+
let(:default_formatter) { double 'Default Formatter' }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
allow(Loggem::Formatters::Json).to receive(:new).and_return(default_formatter)
|
13
|
+
allow(logger).to receive(:info)
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
it "should use the default formatter if none provided" do
|
18
|
+
expect(default_formatter).to receive(:call).with(at: :info, message: 'log message')
|
19
|
+
|
20
|
+
subject.info 'log message'
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
it "should use custom formatter if none provided" do
|
25
|
+
formatter = double 'Formatter'
|
26
|
+
|
27
|
+
expect(formatter).to receive(:call).with(at: :info, message: 'log message')
|
28
|
+
|
29
|
+
subject.formatter = formatter
|
30
|
+
subject.info 'log message'
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
it "should raise error if formatter doesn't respond to call" do
|
35
|
+
expect {
|
36
|
+
subject.formatter = nil
|
37
|
+
}.to raise_error ArgumentError, "Formatter must respond to 'call'"
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
describe 'delegate unknown messages to logger' do
|
45
|
+
it "delegates message 'level=' to the logger" do
|
46
|
+
expect(logger).to receive(:level=).with 'desired log level'
|
47
|
+
|
48
|
+
subject.level = 'desired log level'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
describe 'logging messages' do
|
54
|
+
let(:event) { double 'Event', data: 'event hash' }
|
55
|
+
let(:formatter) { double 'Formatter' }
|
56
|
+
|
57
|
+
before(:each) do
|
58
|
+
allow(formatter).to receive(:call).with('event hash').and_return 'formatted message'
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
[:debug, :info, :warn, :error, :fatal].each do |level|
|
63
|
+
it "should log a #{level} message" do
|
64
|
+
allow(::Loggem::Event).to receive(:new).
|
65
|
+
with(level: level, message: 'raw message', payload: {}, context: {}).
|
66
|
+
and_return(event)
|
67
|
+
expect(logger).to receive(level).with('formatted message')
|
68
|
+
|
69
|
+
subject.formatter = formatter
|
70
|
+
subject.send level, 'raw message'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
it 'should log a message with payload' do
|
76
|
+
allow(::Loggem::Event).to receive(:new).
|
77
|
+
with(level: :info, message: 'raw message', payload: 'payload', context: {}).
|
78
|
+
and_return(event)
|
79
|
+
expect(logger).to receive(:info).with('formatted message')
|
80
|
+
|
81
|
+
subject.formatter = formatter
|
82
|
+
subject.info 'raw message', 'payload'
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
it 'should log multiple messages with the same context' do
|
87
|
+
allow(::Loggem::Event).to receive(:new).
|
88
|
+
with(level: :info, message: 'raw message', payload: {}, context: {request_id: 123}).
|
89
|
+
and_return(event)
|
90
|
+
|
91
|
+
expect(logger).to receive(:info).with('formatted message').twice
|
92
|
+
|
93
|
+
subject.formatter = formatter
|
94
|
+
subject.context[:request_id] = 123
|
95
|
+
|
96
|
+
subject.info 'raw message'
|
97
|
+
subject.info 'raw message'
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
data/spec/loggem_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Loggem do
|
5
|
+
|
6
|
+
describe ".rails_setup" do
|
7
|
+
let(:config) { double 'Config', loggem: double(enabled: true,
|
8
|
+
logger: 'custom logger',
|
9
|
+
formatter: 'custom formatter',
|
10
|
+
context: nil,
|
11
|
+
extensions: nil) }
|
12
|
+
let(:rails) { double 'Rails Application', config: config }
|
13
|
+
let(:loggem) { double 'Loggem instance', context: {} }
|
14
|
+
|
15
|
+
before do
|
16
|
+
module Rails
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should setup rails integration" do
|
21
|
+
allow(::Loggem::Logger).to receive(:new).with('custom logger').and_return(loggem)
|
22
|
+
|
23
|
+
expect(loggem).to receive(:formatter=).with('custom formatter')
|
24
|
+
expect(config).to receive(:logger=).with(loggem)
|
25
|
+
expect(Rails).to receive(:logger=).with(loggem)
|
26
|
+
|
27
|
+
subject.setup_rails(rails)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: loggem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Istvan Demeter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- istvan.demeter@emarsys.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/loggem.rb
|
68
|
+
- lib/loggem/event.rb
|
69
|
+
- lib/loggem/extensions/active_record.rb
|
70
|
+
- lib/loggem/extensions/sequel.rb
|
71
|
+
- lib/loggem/formatters/json.rb
|
72
|
+
- lib/loggem/formatters/key_value.rb
|
73
|
+
- lib/loggem/formatters/raw.rb
|
74
|
+
- lib/loggem/logger.rb
|
75
|
+
- lib/loggem/railtie.rb
|
76
|
+
- lib/loggem/version.rb
|
77
|
+
- loggem.gemspec
|
78
|
+
- spec/loggem/event_spec.rb
|
79
|
+
- spec/loggem/formatters/json_spec.rb
|
80
|
+
- spec/loggem/formatters/key_value_spec.rb
|
81
|
+
- spec/loggem/formatters/raw_spec.rb
|
82
|
+
- spec/loggem/logger_spec.rb
|
83
|
+
- spec/loggem_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
homepage: https://github.com/qw3r/loggem
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.2.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Simple log wrapper with different formatters. Rails/ActiveRecord/Sequel support,
|
109
|
+
so far
|
110
|
+
test_files:
|
111
|
+
- spec/loggem/event_spec.rb
|
112
|
+
- spec/loggem/formatters/json_spec.rb
|
113
|
+
- spec/loggem/formatters/key_value_spec.rb
|
114
|
+
- spec/loggem/formatters/raw_spec.rb
|
115
|
+
- spec/loggem/logger_spec.rb
|
116
|
+
- spec/loggem_spec.rb
|
117
|
+
- spec/spec_helper.rb
|