tty-logger 0.3.0 → 0.4.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
  SHA256:
3
- metadata.gz: af3524110f6873609fc2086063371a728bd63d08d9f9160c8469cef4e5e50d94
4
- data.tar.gz: 4991ed5e387b34fbe8c2e1887ba36ce53e5bc3bc120f957eda6a778202abcf35
3
+ metadata.gz: 1e4b31874b5d1ca9d091b11c0a5d6ca04c3b44a41f1d92c1f9d9b40fe2573c5c
4
+ data.tar.gz: 7f078cf57986ea70885db59ecab0bbd1da6afa93c272ea764208d3c88251b4f9
5
5
  SHA512:
6
- metadata.gz: 66c6892da31f674bcdee76a92334976f19f4447e341cf61c5fce106d5ad7085035d5a580c80f614bc564f4f6567ae6a446aacfe17d7499fb7c65fd4e800d0003
7
- data.tar.gz: 45ee01d044d21a79a85fe55933ef3da2c3aefd58cea31453d61f7007768687e9256447e214de0f90973dc4de136f35eba735e9619c0c17aa9d74b05a32d84090
6
+ metadata.gz: 1c255546632ba09a0aeac9b5e0395dd668576eb30a882342c18b9cf6a5fa525b0c6143e17a6bae3406fdbcb0306c17916c1a5016c62f2e5df816b5b70afeb040
7
+ data.tar.gz: ca12ab5f19b1037d50cc818a940b4e909521ebe7d4338fc552cb0901600eb61d713213f04d576713bfa146e971d050af9599d48d2eecea87013109aa190a39f8
@@ -1,5 +1,18 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.4.0] - 2020-07-29
4
+
5
+ ### Added
6
+
7
+ * Allow editing logger configuration at runtime ([#10](https://github.com/piotrmurach/tty-logger/pull/10))
8
+ * Support for the `<<` streaming operator ([#9](https://github.com/piotrmurach/tty-logger/pull/9)))
9
+
10
+ ### Changed
11
+ * Change gemspec to update pastel version and restrict only to minor version
12
+
13
+ ### Fixed
14
+ * Fix to filter sensitive information from exceptions
15
+
3
16
  ## [v0.3.0] - 2020-01-01
4
17
 
5
18
  ### Added
@@ -27,6 +40,7 @@
27
40
 
28
41
  * Initial implementation and release
29
42
 
43
+ [v0.4.0]: https://github.com/piotrmurach/tty-logger/compare/v0.3.0..v0.4.0
30
44
  [v0.3.0]: https://github.com/piotrmurach/tty-logger/compare/v0.2.0..v0.3.0
31
45
  [v0.2.0]: https://github.com/piotrmurach/tty-logger/compare/v0.1.0..v0.2.0
32
46
  [v0.1.0]: https://github.com/piotrmurach/tty-logger/compare/v0.1.0
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <a href="https://piotrmurach.github.io/tty" target="_blank"><img width="130" src="https://cdn.rawgit.com/piotrmurach/tty/master/images/tty.png" alt="tty logo" /></a>
2
+ <a href="https://piotrmurach.github.io/tty" target="_blank"><img width="130" src="https://github.com/piotrmurach/tty/raw/master/images/tty.png" alt="tty logo" /></a>
3
3
  </div>
4
4
 
5
5
  # TTY::Logger [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
@@ -75,6 +75,8 @@ Or install it yourself as:
75
75
  * [2.6.4 Multiple Handlers](#264-multiple-handlers)
76
76
  * [2.7 Formatters](#27-formatters)
77
77
  * [2.8 Output streams](#28-output-streams)
78
+ * [3. Community Extensions](#3-community-extensions)
79
+ * [3.1 Sentry Handler](#31-sentry-handler)
78
80
 
79
81
  ## 1. Usage
80
82
 
@@ -334,7 +336,7 @@ logger.wait { ["Ready to deploy", {app: "myapp", env: "prod"}] }
334
336
 
335
337
  ### 2.4 Configuration
336
338
 
337
- All the configuration options can be changed globally via `configure` or per logger instance via object initialization.
339
+ All the configuration options can be changed globally via `configure` or per logger instance.
338
340
 
339
341
  * `:filters` - the storage of placeholders to filter sensitive data out from the logs. Defaults to `{}`.
340
342
  * `:formatter` - the formatter used to display structured data. Defaults to `:text`. See [Formatters](#27-formatters) for more details.
@@ -364,6 +366,14 @@ logger = TTY::Logger.new do |config|
364
366
  end
365
367
  ```
366
368
 
369
+ You can also change the logger's configuration at runtime:
370
+
371
+ ```ruby
372
+ logger.configure do |config|
373
+ config.level = :debug
374
+ end
375
+ ```
376
+
367
377
  ### 2.4.1 Metadata
368
378
 
369
379
  The `:metdata` configuration option can include the following symbols:
@@ -735,6 +745,7 @@ TTY::Logger.new do |config|
735
745
  config.handlers = [:console, [:console, formatter: :json]]
736
746
  end
737
747
  ```
748
+
738
749
  ### 2.8 Output Streams
739
750
 
740
751
  By default all log events are output to `stderr`. You can change this using configuration `output` option. Any `IO`-like stream such as file, socket or console can be used. For example, to log all messages to a file do:
@@ -764,6 +775,12 @@ logger = TTY::Logger.new do |config|
764
775
  end
765
776
  ```
766
777
 
778
+ ## 3. Community Extensions
779
+
780
+ ### 3.1 Sentry Handler
781
+
782
+ [tty-logger-raven](https://github.com/ianks/tty-logger-raven) provides an extension for Sentry.io.
783
+
767
784
  ## Development
768
785
 
769
786
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -69,6 +69,13 @@ module TTY
69
69
  yield config
70
70
  end
71
71
 
72
+ # Instance logger configuration
73
+ #
74
+ # @api public
75
+ def configure
76
+ yield @config
77
+ end
78
+
72
79
  # Create a logger instance
73
80
  #
74
81
  # @example
@@ -204,6 +211,24 @@ module TTY
204
211
  compare_levels(level, other_level) != :gt
205
212
  end
206
213
 
214
+ # Logs streaming output.
215
+ #
216
+ # @example
217
+ # logger << "Example output"
218
+ #
219
+ # @api public
220
+ def write(*msg)
221
+ event = Event.new(filter(*msg))
222
+
223
+ @ready_handlers.each do |handler|
224
+ handler.(event)
225
+ end
226
+
227
+ self
228
+ end
229
+
230
+ alias_method :<<, :write
231
+
207
232
  # Log a message given the severtiy level
208
233
  #
209
234
  # @example
@@ -229,7 +254,7 @@ module TTY
229
254
  level: current_level,
230
255
  time: Time.now,
231
256
  pid: Process.pid,
232
- name: /<top\s+\(required\)>|<main>/ =~ label ? current_level : label,
257
+ name: /<top\s+\(required\)>|<main>|<</ =~ label ? current_level : label,
233
258
  path: loc.path,
234
259
  lineno: loc.lineno,
235
260
  method: loc.base_label
@@ -265,21 +290,50 @@ module TTY
265
290
  # Filter message parts for any sensitive information and
266
291
  # replace with placeholder.
267
292
  #
268
- # @param [Array[String]] messages
293
+ # @param [Array[Object]] objects
269
294
  # the messages to filter
270
295
  #
271
296
  # @return [Array[String]]
272
297
  # the filtered message
273
298
  #
274
299
  # @api private
275
- def filter(*messages)
276
- messages.reduce([]) do |acc, msg|
277
- acc << msg.dup.tap do |msg_copy|
278
- @config.filters.message.each do |text|
279
- msg_copy.gsub!(text, @config.filters.mask)
280
- end
300
+ def filter(*objects)
301
+ objects.map do |obj|
302
+ case obj
303
+ when Exception
304
+ backtrace = Array(obj.backtrace).map { |line| swap_filtered(line) }
305
+ copy_error(obj, swap_filtered(obj.message), backtrace)
306
+ else
307
+ swap_filtered(obj.to_s)
308
+ end
309
+ end
310
+ end
311
+
312
+ # Create a new error instance copy
313
+ #
314
+ # @param [Exception] error
315
+ # @param [String] message
316
+ # @param [Array,nil] backtrace
317
+ #
318
+ # @return [Exception]
319
+ #
320
+ # @api private
321
+ def copy_error(error, message, backtrace = nil)
322
+ new_error = error.exception(message)
323
+ new_error.set_backtrace(backtrace)
324
+ new_error
325
+ end
326
+
327
+ # Swap string content for filtered content
328
+ #
329
+ # @param [String] obj
330
+ #
331
+ # @api private
332
+ def swap_filtered(obj)
333
+ obj.dup.tap do |obj_copy|
334
+ @config.filters.message.each do |text|
335
+ obj_copy.gsub!(text, @config.filters.mask)
281
336
  end
282
- acc
283
337
  end
284
338
  end
285
339
  end # Logger
@@ -11,7 +11,7 @@ module TTY
11
11
 
12
12
  attr_reader :backtrace
13
13
 
14
- def initialize(message, fields, metadata)
14
+ def initialize(message, fields = {}, metadata = {})
15
15
  @message = message
16
16
  @fields = fields
17
17
  @metadata = metadata
@@ -29,7 +29,7 @@ module TTY
29
29
  @message.each do |msg|
30
30
  case msg
31
31
  when Exception
32
- @backtrace = msg.backtrace
32
+ @backtrace = msg.backtrace if msg.backtrace
33
33
  else
34
34
  msg
35
35
  end
@@ -114,8 +114,10 @@ module TTY
114
114
  end
115
115
  end
116
116
  fmt << ARROW unless config.metadata.empty?
117
- fmt << color.(style[:symbol])
118
- fmt << color.(style[:label]) + (" " * style[:levelpad])
117
+ unless style.empty?
118
+ fmt << color.(style[:symbol])
119
+ fmt << color.(style[:label]) + (" " * style[:levelpad])
120
+ end
119
121
  fmt << "%-25s" % event.message.join(" ")
120
122
  unless event.fields.empty?
121
123
  pattern, replacement = *@color_pattern
@@ -148,11 +150,11 @@ module TTY
148
150
  #
149
151
  # @api private
150
152
  def configure_styles(event)
151
- style = STYLES.fetch(event.metadata[:name].to_sym, {}).dup
152
- (@styles[event.metadata[:name].to_sym] || {}).each do |k, v|
153
- style[k] = v
154
- end
155
- style
153
+ return {} if event.metadata[:name].nil?
154
+
155
+ STYLES.fetch(event.metadata[:name].to_sym, {})
156
+ .dup
157
+ .merge!(@styles[event.metadata[:name].to_sym] || {})
156
158
  end
157
159
 
158
160
  def configure_color(style)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  class Logger
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-01 00:00:00.000000000 Z
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.0
19
+ version: '0.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.7.0
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '1.5'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '1.5'
26
+ version: '0.8'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -56,22 +42,25 @@ dependencies:
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - "~>"
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
47
  version: '3.0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - "~>"
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
54
  version: '3.0'
69
55
  description: Readable, structured and beautiful terminal logging
70
56
  email:
71
- - me@piotrmurach.com
57
+ - piotr@piotrmurach.com
72
58
  executables: []
73
59
  extensions: []
74
- extra_rdoc_files: []
60
+ extra_rdoc_files:
61
+ - README.md
62
+ - CHANGELOG.md
63
+ - LICENSE.txt
75
64
  files:
76
65
  - CHANGELOG.md
77
66
  - LICENSE.txt
@@ -89,8 +78,7 @@ files:
89
78
  - lib/tty/logger/handlers/stream.rb
90
79
  - lib/tty/logger/levels.rb
91
80
  - lib/tty/logger/version.rb
92
- - tty-logger.gemspec
93
- homepage: https://piotrmurach.github.io/tty
81
+ homepage: https://ttytoolkit.org
94
82
  licenses:
95
83
  - MIT
96
84
  metadata:
@@ -98,7 +86,7 @@ metadata:
98
86
  bug_tracker_uri: https://github.com/piotrmurach/tty-logger/issues
99
87
  changelog_uri: https://github.com/piotrmurach/tty-logger/blob/master/CHANGELOG.md
100
88
  documentation_uri: https://www.rubydoc.info/gems/tty-logger
101
- homepage_uri: https://piotrmurach.github.io/tty
89
+ homepage_uri: https://ttytoolkit.org
102
90
  source_code_uri: https://github.com/piotrmurach/tty-logger
103
91
  post_install_message:
104
92
  rdoc_options: []
@@ -1,36 +0,0 @@
1
- lib = File.expand_path("lib", __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "tty/logger/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "tty-logger"
7
- spec.version = TTY::Logger::VERSION
8
- spec.authors = ["Piotr Murach"]
9
- spec.email = ["me@piotrmurach.com"]
10
- spec.summary = %q{Readable, structured and beautiful terminal logging}
11
- spec.description = %q{Readable, structured and beautiful terminal logging}
12
- spec.homepage = "https://piotrmurach.github.io/tty"
13
- spec.license = "MIT"
14
-
15
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
- spec.metadata["bug_tracker_uri"] = "https://github.com/piotrmurach/tty-logger/issues"
17
- spec.metadata["changelog_uri"] = "https://github.com/piotrmurach/tty-logger/blob/master/CHANGELOG.md"
18
- spec.metadata["documentation_uri"] = "https://www.rubydoc.info/gems/tty-logger"
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/piotrmurach/tty-logger"
21
-
22
- spec.files = Dir["lib/**/*.rb", "tty-logger.gemspec"]
23
- spec.files += Dir["README.md", "CHANGELOG.md", "LICENSE.txt"]
24
- spec.executables = []
25
- spec.require_paths = ["lib"]
26
- spec.required_ruby_version = ">= 2.0.0"
27
-
28
- spec.add_dependency "pastel", "~> 0.7.0"
29
-
30
- spec.add_development_dependency "bundler", ">= 1.5"
31
- spec.add_development_dependency "rake"
32
- spec.add_development_dependency "rspec", "~> 3.0"
33
- if RUBY_VERSION.split(".")[1].to_i > 0
34
- #spec.add_development_dependency "rspec-benchmark", "~> 0.5"
35
- end
36
- end