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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b074c9039eb5fbdba6a406afbf3ebf823b94033e
4
- data.tar.gz: 8284b1c7aa0550b516b7175118904dd689db3b99
3
+ metadata.gz: 28082939a78a1f7c53df3d13057eb6708d33106b
4
+ data.tar.gz: f2228468c82b48c7d7b485bf3d5571fc81150a17
5
5
  SHA512:
6
- metadata.gz: 4967f583dc58d077f368a272be3d29c006ef2ab3f85275f9b9e0efda4a1c4622fe18b19f80433015be54cdeac06f8c043dfa2ac604c217d880c062583222e36e
7
- data.tar.gz: b6b0f9f97554fb7a094677192032b4e302c73978a1f863eaf96f393c27355f50f67c0d2bca5e57a2c67b46564c9ff158b62794b5784223d57d7d5eb47311566f
6
+ metadata.gz: f8d4490eb690b7713d25c154bc558fd10c7b299607e4c2b3e9be3610bebe2eb0a7a3288d0b4c02335b93ea750aa3289402c00b97f766ab4c964a1166a9beeb51
7
+ data.tar.gz: c394db8116c39d18f6c1c867bba80133ef7bc2f4835ddf7f4526ccd1598809c08408555fc1ab9e68a7ca5211ae700904ca2d9887adf85eb9281edf0b6f67d8b6
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Metrics/LineLength:
2
+ Max: 100
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.1
5
- - 2.2.2
3
+ - 2.1.8
4
+ - 2.2.4
6
5
  - 2.3.0
7
- bundler_args: --without development
6
+
7
+ script: 'bundle exec rspec'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 1.2
2
+ Added a silence_logger method to the logger. For compatibility with
3
+ activerecord-session and maybe other gems.
1
4
  # 1.1.1
2
5
  Avoid syntax errors in rubies < 2.3
3
6
 
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  group :development do
4
- gem "mutant-rspec", '~> 0.8'
4
+ gem 'mutant-rspec', '~> 0.8'
5
5
  end
6
6
 
7
7
  # Specify your gem's dependencies in lorekeeper.gemspec
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("../lib", __FILE__))
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:"Verylongmachinenametobe-Pro.local",
18
- component: 'Gilean', version: '0.1.1', trace_id: SecureRandom.hex(16), span_id: SecureRandom.hex(16), parent_span_id: SecureRandom.hex(16)
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 "Runs the code once, sleeping to allow you to attach to it with rbtrace"
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 "Runs benchmarks for the library."
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("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) }
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 "i/s means the number of log messages written into a file per second"
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 "bundler/setup"
4
- require "lorekeeper"
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 "irb"
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, progname = nil, &block)
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
- private
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  # The comment above will make all strings in a current file frozen
3
3
  module Lorekeeper
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.0'
5
5
  end
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 = "lorekeeper"
8
+ spec.name = 'lorekeeper'
9
9
  spec.version = Lorekeeper::VERSION
10
- spec.authors = ["Jordi Polo"]
11
- spec.email = ["mumismo@gmail.com"]
10
+ spec.authors = ['Jordi Polo']
11
+ spec.email = ['mumismo@gmail.com']
12
12
 
13
- spec.summary = %q{ Very fast JSON logger }
14
- spec.description = %q{ Opinionated logger which outputs messages in JSON format }
15
- spec.homepage = "http://www.gihub.com/jordipolo/lorekeeper"
16
- spec.license = "MIT"
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 = "exe"
19
+ spec.bindir = 'exe'
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_dependency 'oj', '~> 2.14'
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.10"
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'
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.1.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-15 00:00:00.000000000 Z
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.10'
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.10'
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