lorekeeper 1.5.1 → 1.6.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: c04d30160d6ec787f1842265407e9187cdbb707d
4
- data.tar.gz: 56de4e4f9d1c4e19a558c5744d94cbff1a5f03da
3
+ metadata.gz: b7f9cc1ad4f01d7ba6b9301762f3c2be2a9b865f
4
+ data.tar.gz: df9ed29c2ff9294cbc0dc8aa6bd7e01373527a6f
5
5
  SHA512:
6
- metadata.gz: 2920b67cc06bd8f56fe1b1f3897f8169b3bc1bbe172cc6ecbde1ab5cf92460de0162dacda774f5c43b1d6d4b8248f1491893920da76a615106f8ae9ec51eab4e
7
- data.tar.gz: de57889866ad7d8fb0d4eb084363127494b89ab7d7bf1d237cfd8cca73a9e88d39dd041c96223a08054384298c9e42d1564ea3125a9e7d1d89b7d055e35f8d0b
6
+ metadata.gz: 1010ae953b8a32ae377dbe4f6e011f5399a50a4e8a3f5988a889892c3ddde6cc16f395673889520016d4c725a6a2f99910e4e4ebf8ab3c58037e36156e893639
7
+ data.tar.gz: 2532bbf0078364bc8cb14652086f0492e8aaf1c3a2f805c625cb395cab851ec36ce8223d566551c6729b09338e262118d5a32c8eb5a774b2eb579a4a5552c4bf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 1.6.0
2
+ * Adds 'exception' to simple logger to unify APIs
3
+
1
4
  # 1.5.1
2
5
  * Updating version to resolve issue with mistakenly created 1.5.0 gem version
3
6
 
data/lib/lorekeeper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'lorekeeper/version'
2
2
  require 'lorekeeper/fast_logger'
3
+ require 'lorekeeper/simple_logger'
3
4
  require 'lorekeeper/json_logger'
4
5
  require 'lorekeeper/multi_logger'
@@ -119,40 +119,4 @@ module Lorekeeper
119
119
  end
120
120
  end
121
121
 
122
- # Simple logger which tries to have an easy to see output.
123
- class SimpleLogger < FastLogger
124
- # From http://misc.flogisoft.com/bash/tip_colors_and_formatting
125
- # 39: default for the theme
126
- # 33: yellow
127
- # 31: red
128
- # 37: light gray
129
- SEVERITY_TO_COLOR_MAP = {
130
- DEBUG => '39'.freeze,
131
- INFO => DEBUG,
132
- WARN => '33'.freeze,
133
- ERROR => '31'.freeze,
134
- FATAL => ERROR,
135
- UNKNOWN => '37'.freeze
136
- }.freeze
137
-
138
- # \e[colorm sets a color \e[0m resets all properties
139
- def log_data(severity, message)
140
- color = SEVERITY_TO_COLOR_MAP[severity]
141
- @iodevice.write("\e[#{color}m#{message}\e[0m\n")
142
- end
143
-
144
- def inspect
145
- "Lorekeeper Simple logger. IO: #{@file.inspect}"
146
- end
147
-
148
- # Extending the logger API with methods error_with_data, etc
149
- LOGGING_METHODS.each do |method_name|
150
- define_method "#{method_name}_with_data", ->(message_param = nil, data = {}, &block) do
151
- return true if METHOD_SEVERITY_MAP[method_name] < @level
152
- log_data(METHOD_SEVERITY_MAP[method_name], "#{message_param}, data: #{data}")
153
- end
154
- end
155
- end
156
-
157
-
158
122
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ # The comment above will make all strings in a current file frozen
3
+ require 'lorekeeper/fast_logger'
4
+
5
+ module Lorekeeper
6
+ # Simple logger provides a logger which outputs messages in a colorized simple text format.
7
+ class SimpleLogger < FastLogger
8
+ # From http://misc.flogisoft.com/bash/tip_colors_and_formatting
9
+ # 39: default for the theme
10
+ # 33: yellow
11
+ # 31: red
12
+ # 37: light gray
13
+ SEVERITY_TO_COLOR_MAP = {
14
+ DEBUG => '39'.freeze,
15
+ INFO => DEBUG,
16
+ WARN => '33'.freeze,
17
+ ERROR => '31'.freeze,
18
+ FATAL => ERROR,
19
+ UNKNOWN => '37'.freeze
20
+ }.freeze
21
+
22
+ # \e[colorm sets a color \e[0m resets all properties
23
+ def log_data(severity, message)
24
+ color = SEVERITY_TO_COLOR_MAP[severity]
25
+ @iodevice.write("\e[#{color}m#{message}\e[0m\n")
26
+ end
27
+
28
+ def inspect
29
+ "Lorekeeper Simple logger. IO: #{@file.inspect}"
30
+ end
31
+
32
+ # Extending the logger API with methods error_with_data, etc
33
+ LOGGING_METHODS.each do |method_name|
34
+ define_method "#{method_name}_with_data", ->(message_param = nil, data = {}, &block) do
35
+ return true if METHOD_SEVERITY_MAP[method_name] < @level
36
+ log_data(METHOD_SEVERITY_MAP[method_name], "#{message_param}, data: #{data}")
37
+ end
38
+ end
39
+
40
+ def exception(exception, custom_message = nil, custom_data = nil)
41
+ if exception.is_a?(Exception)
42
+ backtrace = exception.backtrace || []
43
+ message = custom_message || exception.message
44
+ error_with_data("#{exception.class}: #{message}", backtrace.join("\n"))
45
+ else
46
+ log_data(:warning, 'Logger exception called without exception class.')
47
+ error_with_data("#{exception.class}: #{exception.inspect} #{custom_message}", custom_data)
48
+ end
49
+ end
50
+ end
51
+
52
+ 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.5.1'.freeze
4
+ VERSION = '1.6.0'.freeze
5
5
  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.5.1
4
+ version: 1.6.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-09-12 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -144,6 +144,7 @@ files:
144
144
  - lib/lorekeeper/fast_logger.rb
145
145
  - lib/lorekeeper/json_logger.rb
146
146
  - lib/lorekeeper/multi_logger.rb
147
+ - lib/lorekeeper/simple_logger.rb
147
148
  - lib/lorekeeper/version.rb
148
149
  - lorekeeper.gemspec
149
150
  homepage: http://www.github.com/jordipolo/lorekeeper