logasm 0.2.5 → 0.2.6

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: 5d617fe6f30cdd7d5019618e9d4156d558539860
4
- data.tar.gz: f24dfbacbc3c18d94839770304c5c7ccdf841dce
3
+ metadata.gz: 1c37a9355e4d9426215d500f6fdb50a22954c2e4
4
+ data.tar.gz: 58289a6f19d649b8c405638428a43938ca586132
5
5
  SHA512:
6
- metadata.gz: 902f38928193719f4c23f4297da8049aa785adcab3d6c4a1620d6a7f716cdd9b90b991567f24dceb51b5fd3dd0015d5559173b1d0ac3673b81f4a37b1f4e44e4
7
- data.tar.gz: 66ad45f23be1dbb5c0e07cfa21222641149d48f7db3946f61ad5b32f59afafb4f6bdd5b0f7e80be563bbd9c2a8101721a4abefe71dbf15a7dde49ac6ee394da6
6
+ metadata.gz: 6712eee9ed98800f0be30370509848b0c8a70b587e278fd63c7e742d5949aa0c3703b70cb17bc2c8a5d9d3cb02ab7e548c1d9a06c65a5f31711d3628edb55f7e
7
+ data.tar.gz: e60591d1432b92075757b0fb76acbd7613f3f46fb6ec60af58bb2bd0e54331a90f73e301b3338f8f3667f4feabc547821a8bbf99c613aac288f6193e4309cbff
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- logasm (0.2.5)
4
+ logasm (0.2.6)
5
5
  inflecto
6
6
 
7
7
  GEM
data/lib/logasm.rb CHANGED
@@ -5,6 +5,8 @@ require_relative 'logasm/adapters'
5
5
  require_relative 'logasm/utils'
6
6
  require_relative 'logasm/null_logger'
7
7
 
8
+ LOG_LEVEL_QUERY_METHODS = [:debug?, :info?, :warn?, :error?, :fatal?]
9
+
8
10
  class Logasm
9
11
  def self.build(service_name, loggers_config)
10
12
  loggers_config ||= {stdout: nil}
@@ -38,6 +40,12 @@ class Logasm
38
40
  log :fatal, *args
39
41
  end
40
42
 
43
+ LOG_LEVEL_QUERY_METHODS.each do |method|
44
+ define_method(method) do
45
+ @adapters.any? {|adapter| adapter.public_send(method) }
46
+ end
47
+ end
48
+
41
49
  private
42
50
 
43
51
  def log(level, *args)
@@ -1,11 +1,15 @@
1
1
  require 'socket'
2
2
  require_relative 'logstash_adapter/formatter'
3
+ require 'forwardable'
3
4
 
4
5
  class Logasm
5
6
  module Adapters
6
7
  class LogstashAdapter
8
+ extend Forwardable
7
9
  attr_reader :logger
8
10
 
11
+ def_delegators :@logger, :debug?, :info?, :warn?, :error?, :fatal?
12
+
9
13
  def initialize(level, service, arguments = {})
10
14
  host = arguments.fetch(:host)
11
15
  port = arguments.fetch(:port)
@@ -30,6 +30,26 @@ class Logasm
30
30
  end
31
31
  end
32
32
 
33
+ def debug?
34
+ meets_threshold?(:debug)
35
+ end
36
+
37
+ def info?
38
+ meets_threshold?(:info)
39
+ end
40
+
41
+ def warn?
42
+ meets_threshold?(:warn)
43
+ end
44
+
45
+ def error?
46
+ meets_threshold?(:error)
47
+ end
48
+
49
+ def fatal?
50
+ meets_threshold?(:fatal)
51
+ end
52
+
33
53
  private
34
54
 
35
55
  def meets_threshold?(level)
@@ -1,8 +1,14 @@
1
+ require 'forwardable'
2
+
1
3
  class Logasm
2
4
  module Adapters
3
5
  class StdoutAdapter
6
+ extend Forwardable
7
+
4
8
  attr_reader :logger
5
9
 
10
+ def_delegators :@logger, :debug?, :info?, :warn?, :error?, :fatal?
11
+
6
12
  def initialize(level, *)
7
13
  @logger = Logger.new(STDOUT)
8
14
  @logger.level = level
data/logasm.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "logasm"
7
- gem.version = '0.2.5'
7
+ gem.version = '0.2.6'
8
8
  gem.authors = ["Salemove"]
9
9
  gem.email = ["support@salemove.com"]
10
10
  gem.description = %q{It's logasmic}
data/spec/logasm_spec.rb CHANGED
@@ -74,4 +74,44 @@ describe Logasm do
74
74
  logasm.info 'test message', test: 'data'
75
75
  end
76
76
  end
77
+
78
+ context 'log level queries' do
79
+ context 'when one adapter has debug level' do
80
+ let(:logger) do
81
+ described_class.build(
82
+ 'test_service',
83
+ stdout: {level: 'debug'},
84
+ logstash: {level: 'info', host: '127.0.0.1', port: 5228 },
85
+ rabbitmq: {level: 'fatal'},
86
+ )
87
+ end
88
+
89
+ it 'responds true to debug? and higher levels' do
90
+ expect(logger.debug?).to be(true)
91
+ expect(logger.info?).to be(true)
92
+ expect(logger.warn?).to be(true)
93
+ expect(logger.error?).to be(true)
94
+ expect(logger.fatal?).to be(true)
95
+ end
96
+ end
97
+
98
+ context 'when one adapter has info level' do
99
+ let(:logger) do
100
+ described_class.build(
101
+ 'test_service',
102
+ rabbitmq: {level: 'info'},
103
+ stdout: {level: 'warn'},
104
+ logstash: {level: 'warn', host: '127.0.0.1', port: 5228 },
105
+ )
106
+ end
107
+
108
+ it 'responds true to info? and higher levels' do
109
+ expect(logger.debug?).to be(false)
110
+ expect(logger.info?).to be(true)
111
+ expect(logger.warn?).to be(true)
112
+ expect(logger.error?).to be(true)
113
+ expect(logger.fatal?).to be(true)
114
+ end
115
+ end
116
+ end
77
117
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salemove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflecto