lorekeeper 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.travis.yml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -1
- data/README.md +2 -0
- data/Rakefile +12 -14
- data/bin/console +3 -3
- data/lib/lorekeeper/fast_logger.rb +12 -6
- data/lib/lorekeeper/json_logger.rb +3 -3
- data/lib/lorekeeper/multi_logger.rb +2 -1
- data/lib/lorekeeper/version.rb +1 -1
- data/lorekeeper.gemspec +16 -17
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28082939a78a1f7c53df3d13057eb6708d33106b
|
4
|
+
data.tar.gz: f2228468c82b48c7d7b485bf3d5571fc81150a17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8d4490eb690b7713d25c154bc558fd10c7b299607e4c2b3e9be3610bebe2eb0a7a3288d0b4c02335b93ea750aa3289402c00b97f766ab4c964a1166a9beeb51
|
7
|
+
data.tar.gz: c394db8116c39d18f6c1c867bba80133ef7bc2f4835ddf7f4526ccd1598809c08408555fc1ab9e68a7ca5211ae700904ca2d9887adf85eb9281edf0b6f67d8b6
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Lorekeeper
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/JordiPolo/lorekeeper.svg?branch=master)](https://travis-ci.org/JordiPolo/lorekeeper)
|
4
|
+
|
3
5
|
LoreKeeper contains a highly optimized JSON logger. It outputs messages as JSON and let the users to add their own customized fields.
|
4
6
|
When used without extra fields it outputs 20% faster than the standard Logger for messages not longer than one line of text.
|
5
7
|
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'benchmark/ips'
|
|
5
5
|
require 'byebug'
|
6
6
|
require 'rbtrace'
|
7
7
|
|
8
|
-
$LOAD_PATH.unshift(File.expand_path(
|
8
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
9
9
|
$LOAD_PATH.uniq!
|
10
10
|
|
11
11
|
require 'lorekeeper'
|
@@ -14,8 +14,10 @@ require 'logger'
|
|
14
14
|
def create_logger
|
15
15
|
logfile = Tempfile.new('my_test_log.log')
|
16
16
|
extra_fields = {
|
17
|
-
machine:
|
18
|
-
|
17
|
+
machine: 'Verylongmachinenametobe-Pro.local', component: 'Gilean', version: '0.1.1',
|
18
|
+
trace_id: SecureRandom.hex(16),
|
19
|
+
span_id: SecureRandom.hex(16),
|
20
|
+
parent_span_id: SecureRandom.hex(16)
|
19
21
|
}
|
20
22
|
log = Lorekeeper::JSONLogger.new(logfile)
|
21
23
|
log.add_fields(extra_fields)
|
@@ -28,7 +30,7 @@ def create_simple_logger
|
|
28
30
|
end
|
29
31
|
|
30
32
|
# This task is used to help development of Lorekeeper. Use together with rbtrace
|
31
|
-
desc
|
33
|
+
desc 'Runs the code once, sleeping to allow you to attach to it with rbtrace'
|
32
34
|
task :run_once do
|
33
35
|
contents = 'This is a test, this is only a test. Do not worry about these contents.'
|
34
36
|
long_contents = contents * 100
|
@@ -38,11 +40,9 @@ task :run_once do
|
|
38
40
|
log.error(long_contents)
|
39
41
|
end
|
40
42
|
|
41
|
-
|
42
43
|
# This task is used to help development of Lorekeeer. Make sure it is fast enough for your app.
|
43
|
-
desc
|
44
|
+
desc 'Runs benchmarks for the library.'
|
44
45
|
task :benchmark do
|
45
|
-
|
46
46
|
contents = 'This is a test, this is only a test. Do not worry about these contents.'
|
47
47
|
long_contents = contents * 100
|
48
48
|
|
@@ -50,14 +50,12 @@ task :benchmark do
|
|
50
50
|
simple_log = create_simple_logger
|
51
51
|
|
52
52
|
Benchmark.ips do |bm|
|
53
|
-
bm.report(
|
54
|
-
bm.report(
|
55
|
-
bm.report(
|
56
|
-
bm.report(
|
53
|
+
bm.report('short content') { log.error(contents) }
|
54
|
+
bm.report('Logger short content') { simple_log.info(contents) }
|
55
|
+
bm.report('long content') { log.info(long_contents) }
|
56
|
+
bm.report('Logger long content') { simple_log.info(long_contents) }
|
57
57
|
bm.compare!
|
58
58
|
end
|
59
59
|
|
60
|
-
puts
|
61
|
-
|
60
|
+
puts 'i/s means the number of log messages written into a file per second'
|
62
61
|
end
|
63
|
-
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'lorekeeper'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "lorekeeper"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# The comment above will make all strings in a current file frozen
|
3
|
-
|
4
3
|
require 'logger'
|
5
4
|
|
6
5
|
module Lorekeeper
|
7
|
-
|
8
6
|
# Very simple, very fast logger
|
9
7
|
class FastLogger
|
10
8
|
include ::Logger::Severity # contains the levels constants: DEBUG, ERROR, etc.
|
@@ -23,7 +21,7 @@ module Lorekeeper
|
|
23
21
|
end
|
24
22
|
|
25
23
|
LOGGING_METHODS = %i(debug info warn error fatal)
|
26
|
-
METHOD_SEVERITY_MAP = {debug: DEBUG, info: INFO, warn: WARN, error: ERROR, fatal: FATAL}
|
24
|
+
METHOD_SEVERITY_MAP = { debug: DEBUG, info: INFO, warn: WARN, error: ERROR, fatal: FATAL }
|
27
25
|
|
28
26
|
# We define the behaviour of all the usual logging methods
|
29
27
|
# We support a string as a parameter and also a block
|
@@ -34,12 +32,20 @@ module Lorekeeper
|
|
34
32
|
end
|
35
33
|
|
36
34
|
# This is part of the standard Logger API, we need this to be compatible
|
37
|
-
def add(severity, message_param = nil,
|
35
|
+
def add(severity, message_param = nil, _ = nil, &block)
|
38
36
|
return true if severity < @level
|
39
37
|
message = message_param || (block && block.call)
|
40
38
|
log_data(severity, message.freeze)
|
41
39
|
end
|
42
40
|
|
41
|
+
# Some gems like to add this method. For instance:
|
42
|
+
# https://github.com/rails/activerecord-session_store
|
43
|
+
# To avoid needing to monkey-patch Lorekeeper just to get this method, we are adding a simple
|
44
|
+
# non-functional version here.
|
45
|
+
def silence_logger(&block)
|
46
|
+
yield if block_given?
|
47
|
+
end
|
48
|
+
|
43
49
|
# inherited classes probably want to reimplement this
|
44
50
|
def log_data(_severity, message)
|
45
51
|
@iodevice.write(message)
|
@@ -48,12 +54,13 @@ module Lorekeeper
|
|
48
54
|
private
|
49
55
|
|
50
56
|
require 'monitor'
|
57
|
+
# Mutex to avoid broken lines when multiple threads access the log file
|
51
58
|
class LogDeviceMutex
|
52
59
|
include MonitorMixin
|
53
60
|
end
|
54
61
|
|
62
|
+
# Very fast class to write to a log file.
|
55
63
|
class LogDevice
|
56
|
-
|
57
64
|
def initialize(file)
|
58
65
|
@iodevice = to_iodevice(file)
|
59
66
|
@iomutex = LogDeviceMutex.new
|
@@ -85,6 +92,5 @@ module Lorekeeper
|
|
85
92
|
puts "File #{filename} can't be open for logging. #{e.message}"
|
86
93
|
end
|
87
94
|
end
|
88
|
-
|
89
95
|
end
|
90
96
|
end
|
@@ -30,7 +30,7 @@ module Lorekeeper
|
|
30
30
|
LOGGING_METHODS.each do |method_name|
|
31
31
|
define_method "#{method_name}_with_data", ->(message_param = nil, data = {}, &block) do
|
32
32
|
return true if METHOD_SEVERITY_MAP[method_name] < @level
|
33
|
-
extra_fields = {'data' => (data || {}) }
|
33
|
+
extra_fields = { 'data' => (data || {}) }
|
34
34
|
with_extra_fields(extra_fields) { # Using do/end here only valid on Ruby>= 2.3
|
35
35
|
add(METHOD_SEVERITY_MAP[method_name], message_param, nil, &block)
|
36
36
|
}
|
@@ -81,9 +81,9 @@ module Lorekeeper
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
private
|
85
85
|
|
86
|
-
THREAD_KEY = 'lorekeeper_jsonlogger_key'.freeze #Shared by all threads but unique by thread
|
86
|
+
THREAD_KEY = 'lorekeeper_jsonlogger_key'.freeze # Shared by all threads but unique by thread
|
87
87
|
MESSAGE = 'message'.freeze
|
88
88
|
TIMESTAMP = 'timestamp'.freeze
|
89
89
|
DATE_FORMAT = '%FT%T.%L%z'.freeze
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
module Lorekeeper
|
3
3
|
# Allows to create a logger that will pass information to any logger registered
|
4
4
|
# It is useful so send the same message thought different loggers to different sinks
|
@@ -6,6 +6,7 @@ module Lorekeeper
|
|
6
6
|
def initialize
|
7
7
|
@loggers = []
|
8
8
|
end
|
9
|
+
|
9
10
|
def add_logger(logger)
|
10
11
|
@loggers << logger
|
11
12
|
end
|
data/lib/lorekeeper/version.rb
CHANGED
data/lorekeeper.gemspec
CHANGED
@@ -5,29 +5,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require 'lorekeeper/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'lorekeeper'
|
9
9
|
spec.version = Lorekeeper::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
10
|
+
spec.authors = ['Jordi Polo']
|
11
|
+
spec.email = ['mumismo@gmail.com']
|
12
12
|
|
13
|
-
spec.summary =
|
14
|
-
spec.description =
|
15
|
-
spec.homepage =
|
16
|
-
spec.license =
|
13
|
+
spec.summary = ' Very fast JSON logger '
|
14
|
+
spec.description = ' Opinionated logger which outputs messages in JSON format '
|
15
|
+
spec.homepage = 'http://www.gihub.com/jordipolo/lorekeeper'
|
16
|
+
spec.license = 'MIT'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
-
spec.bindir =
|
19
|
+
spec.bindir = 'exe'
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
22
22
|
|
23
23
|
spec.add_dependency 'oj', '~> 2.14'
|
24
24
|
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
28
|
+
spec.add_development_dependency 'benchmark-ips', '~> 2.3'
|
29
|
+
spec.add_development_dependency 'timecop', '~> 0.8'
|
30
|
+
spec.add_development_dependency 'byebug', '~> 8.0'
|
31
|
+
spec.add_development_dependency 'rbtrace', '~> 0.4'
|
33
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lorekeeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordi Polo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.7'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,6 +131,7 @@ extra_rdoc_files: []
|
|
131
131
|
files:
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
134
135
|
- ".travis.yml"
|
135
136
|
- CHANGELOG.md
|
136
137
|
- Gemfile
|