elastic-logger 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e5c23a7384acfb6540c80fe79f111d900c014b6
4
- data.tar.gz: 9fcc4baf767189184765b585f2a0088293ec0942
3
+ metadata.gz: 3f706187e7572cff284bce76972f00b348e37ac3
4
+ data.tar.gz: c1f8c9b90bb6f127b39f2cc444954574021d4dc8
5
5
  SHA512:
6
- metadata.gz: 33ad674a50f30e2d3e8afa558c495935ef0a399993f252c32e9a53709b57cab99a992cc27c5439fb45e6eaddedaead6a47f6a626a84f51ee0825fcc1829a248b
7
- data.tar.gz: 1979f51570eab184e2e4fa78a5bda96ea631fc2770ff9881022b430fa0708763109ecfb807e2cfa8f48d97d5400404161f0ac2256968aa33d314113aa8683762
6
+ metadata.gz: 0cc347c8cabd2e79eeb39fc1f606bfed4f1e27bf708268a4e8ddef23052d18b89de245582a5606c2794e07fec6c552a4bd858b4a6be00bffb2dd8114ed6ebf58
7
+ data.tar.gz: c4dad1793d30c40f5ea0abcece658a52a7204750041f18a575b07e63b8080ae69680e7d22193bf5bfd0269dd230e43b0fa938b8f9b7b634c2e317f756882077a
data/README.md CHANGED
@@ -40,19 +40,17 @@ With this file we create two logs, one which will log to elastic, and one to sta
40
40
 
41
41
  ```yml
42
42
  sidekiq_monitor:
43
- writer: 'InfaktLogger::ElastickWriter'
44
- rotate: 30 # how many days keep in elk
45
- backup: 90 # how many days keep backup, 0 for no backup, -1 for infinite
46
- api_requests:
47
- writer: 'InfaktLogger::DiskWriter'
43
+ writer: 'InfaktLogger::ElkWriter'
48
44
  delete:
49
45
  type: 'standard' # never if you want to keep that log
50
46
  unit: 'days' # One of seconds, minutes, hours, days, weeks, months, or years.
51
- unit_count: # The number of unit (s). unit_count * unit will be calculated out to the relative number of seconds.
47
+ unit_count: 2 # The number of unit (s). unit_count * unit will be calculated out to the relative number of seconds.
52
48
  backup:
53
49
  type: 'standard' # infinite if you want to keep that log, never for no backups
54
50
  unit: 'days' # One of seconds, minutes, hours, days, weeks, months, or years.
55
- unit_count: # The number of unit (s). unit_count * unit will be calculated out to the relative number of seconds.
51
+ unit_count: 2 # The number of unit (s). unit_count * unit will be calculated out to the relative number of seconds.
52
+ api_requests:
53
+ writer: 'InfaktLogger::DiskWriter'
56
54
  ```
57
55
  ### Usage
58
56
 
@@ -1,12 +1,13 @@
1
1
  module ElasticLogger
2
2
  class Configuration
3
- attr_accessor :host, :types_file, :path, :prefix
3
+ attr_accessor :host, :types_file, :path, :prefix, :log_level
4
4
 
5
5
  def initialize
6
6
  @host = 'localhost:9200'
7
7
  @types_file = 'config/elastic_log_types.yml'
8
8
  @path = 'log'
9
9
  @prefix = ''
10
+ @log_level = ::Logger::DEBUG
10
11
  end
11
12
  end
12
13
  end
@@ -5,8 +5,8 @@ module ElasticLogger
5
5
  @name = name
6
6
  end
7
7
 
8
- def log(hash)
9
- logger.info(hash)
8
+ def log(severity, hash)
9
+ logger.send(severity, hash)
10
10
  end
11
11
 
12
12
  private
@@ -7,17 +7,18 @@ module ElasticLogger
7
7
  @name = name
8
8
  end
9
9
 
10
- def log(hash)
11
- client.index(index: index, type: name, body: build_log(hash))
10
+ def log(severity, hash)
11
+ client.index(index: index, type: name, body: build_log(severity, hash))
12
12
  end
13
13
 
14
14
  private
15
15
  attr_reader :config, :name
16
16
 
17
- def build_log(hash)
17
+ def build_log(severity, hash)
18
18
  {
19
19
  "@fields" => hash,
20
- "@timestamp" => timestamp.iso8601(3)
20
+ "@timestamp" => timestamp.iso8601(3),
21
+ "@severity" => severity
21
22
  }
22
23
  end
23
24
 
@@ -2,16 +2,29 @@ require 'elastic-logger/types'
2
2
 
3
3
  module ElasticLogger
4
4
  class Logger
5
+
5
6
  def initialize(name)
6
7
  @name = name.to_s
7
8
  end
8
9
 
9
- def log(hash)
10
- writer.log(hash)
10
+ # def debug(hash)
11
+ # def error(hash)
12
+ # def fatal(hash)
13
+ # def info(hash)
14
+ # def unknown(hash)
15
+ # def warn(hash)
16
+ %w(debug error fatal info unknown warn).each do |severity|
17
+ define_method(severity) do |hash|
18
+ log(hash, severity.to_s.upcase)
19
+ end
20
+ end
21
+
22
+ def log(msg, severity = 'UNKNOWN')
23
+ return true if ::Logger.const_get(severity) < config.log_level
24
+
25
+ writer.log(severity, format(msg))
26
+ true
11
27
  end
12
- alias_method :debug, :log
13
- alias_method :info, :log
14
- alias_method :warn, :log
15
28
 
16
29
  private
17
30
  attr_reader :name
@@ -21,6 +34,14 @@ module ElasticLogger
21
34
  Object.const_get(writer).new(name: log_name, config: config)
22
35
  end
23
36
 
37
+ def format(msg)
38
+ case msg
39
+ when String then { msg: msg }
40
+ when Array then msg.map.with_index { |v, i| [i, v] }.to_h
41
+ else msg
42
+ end
43
+ end
44
+
24
45
  def log_name
25
46
  [config.prefix, name].map(&:to_s).reject(&:empty?).join("_")
26
47
  end
@@ -1,3 +1,3 @@
1
1
  module ElasticLogger
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Radosław Woźnik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-27 00:00:00.000000000 Z
12
+ date: 2017-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler