tty-logger 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +69 -8
  4. data/lib/tty/logger.rb +14 -10
  5. data/lib/tty/logger/config.rb +34 -3
  6. data/lib/tty/logger/data_filter.rb +121 -0
  7. data/lib/tty/logger/handlers/console.rb +13 -3
  8. data/lib/tty/logger/version.rb +1 -1
  9. data/tty-logger.gemspec +4 -6
  10. metadata +4 -38
  11. data/Rakefile +0 -8
  12. data/examples/child.rb +0 -9
  13. data/examples/console.rb +0 -22
  14. data/examples/custom_type.rb +0 -27
  15. data/examples/error.rb +0 -11
  16. data/examples/handler.rb +0 -19
  17. data/examples/log.rb +0 -9
  18. data/examples/output.rb +0 -15
  19. data/examples/override.rb +0 -29
  20. data/examples/stream.rb +0 -22
  21. data/spec/perf/json_formatter_spec.rb +0 -29
  22. data/spec/perf/log_spec.rb +0 -21
  23. data/spec/perf/text_formatter_spec.rb +0 -29
  24. data/spec/spec_helper.rb +0 -31
  25. data/spec/unit/add_handler_spec.rb +0 -25
  26. data/spec/unit/config_spec.rb +0 -109
  27. data/spec/unit/copy_spec.rb +0 -27
  28. data/spec/unit/event_spec.rb +0 -22
  29. data/spec/unit/exception_spec.rb +0 -45
  30. data/spec/unit/filter_spec.rb +0 -32
  31. data/spec/unit/formatter_spec.rb +0 -70
  32. data/spec/unit/formatters/json_spec.rb +0 -41
  33. data/spec/unit/formatters/text_spec.rb +0 -82
  34. data/spec/unit/handler_spec.rb +0 -83
  35. data/spec/unit/handlers/custom_spec.rb +0 -26
  36. data/spec/unit/handlers/null_spec.rb +0 -15
  37. data/spec/unit/handlers/stream_spec.rb +0 -72
  38. data/spec/unit/levels_spec.rb +0 -40
  39. data/spec/unit/log_at_spec.rb +0 -34
  40. data/spec/unit/log_metadata_spec.rb +0 -55
  41. data/spec/unit/log_spec.rb +0 -203
  42. data/spec/unit/output_spec.rb +0 -40
  43. data/tasks/console.rake +0 -11
  44. data/tasks/coverage.rake +0 -11
  45. data/tasks/spec.rake +0 -34
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  class Logger
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
data/tty-logger.gemspec CHANGED
@@ -19,13 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.metadata["homepage_uri"] = spec.homepage
20
20
  spec.metadata["source_code_uri"] = "https://github.com/piotrmurach/tty-logger"
21
21
 
22
- spec.files = Dir['{lib,spec,examples}/**/*.rb']
23
- spec.files += Dir['tasks/*', 'tty-logger.gemspec']
24
- spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
25
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.files = Dir["lib/**/*.rb", "tty-logger.gemspec"]
23
+ spec.files += Dir["README.md", "CHANGELOG.md", "LICENSE.txt"]
24
+ spec.executables = []
26
25
  spec.require_paths = ["lib"]
27
-
28
- spec.required_ruby_version = '>= 2.0.0'
26
+ spec.required_ruby_version = ">= 2.0.0"
29
27
 
30
28
  spec.add_dependency "pastel", "~> 0.7.0"
31
29
 
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.2.0
4
+ version: 0.3.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: 2019-09-30 00:00:00.000000000 Z
11
+ date: 2020-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -76,19 +76,10 @@ files:
76
76
  - CHANGELOG.md
77
77
  - LICENSE.txt
78
78
  - README.md
79
- - Rakefile
80
- - examples/child.rb
81
- - examples/console.rb
82
- - examples/custom_type.rb
83
- - examples/error.rb
84
- - examples/handler.rb
85
- - examples/log.rb
86
- - examples/output.rb
87
- - examples/override.rb
88
- - examples/stream.rb
89
79
  - lib/tty-logger.rb
90
80
  - lib/tty/logger.rb
91
81
  - lib/tty/logger/config.rb
82
+ - lib/tty/logger/data_filter.rb
92
83
  - lib/tty/logger/event.rb
93
84
  - lib/tty/logger/formatters/json.rb
94
85
  - lib/tty/logger/formatters/text.rb
@@ -98,31 +89,6 @@ files:
98
89
  - lib/tty/logger/handlers/stream.rb
99
90
  - lib/tty/logger/levels.rb
100
91
  - lib/tty/logger/version.rb
101
- - spec/perf/json_formatter_spec.rb
102
- - spec/perf/log_spec.rb
103
- - spec/perf/text_formatter_spec.rb
104
- - spec/spec_helper.rb
105
- - spec/unit/add_handler_spec.rb
106
- - spec/unit/config_spec.rb
107
- - spec/unit/copy_spec.rb
108
- - spec/unit/event_spec.rb
109
- - spec/unit/exception_spec.rb
110
- - spec/unit/filter_spec.rb
111
- - spec/unit/formatter_spec.rb
112
- - spec/unit/formatters/json_spec.rb
113
- - spec/unit/formatters/text_spec.rb
114
- - spec/unit/handler_spec.rb
115
- - spec/unit/handlers/custom_spec.rb
116
- - spec/unit/handlers/null_spec.rb
117
- - spec/unit/handlers/stream_spec.rb
118
- - spec/unit/levels_spec.rb
119
- - spec/unit/log_at_spec.rb
120
- - spec/unit/log_metadata_spec.rb
121
- - spec/unit/log_spec.rb
122
- - spec/unit/output_spec.rb
123
- - tasks/console.rake
124
- - tasks/coverage.rake
125
- - tasks/spec.rake
126
92
  - tty-logger.gemspec
127
93
  homepage: https://piotrmurach.github.io/tty
128
94
  licenses:
@@ -149,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
115
  - !ruby/object:Gem::Version
150
116
  version: '0'
151
117
  requirements: []
152
- rubygems_version: 3.0.3
118
+ rubygems_version: 3.1.2
153
119
  signing_key:
154
120
  specification_version: 4
155
121
  summary: Readable, structured and beautiful terminal logging
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
3
- FileList['tasks/**/*.rake'].each(&method(:import))
4
-
5
- desc 'Run all specs'
6
- task ci: %w[ spec ]
7
-
8
- task default: :spec
data/examples/child.rb DELETED
@@ -1,9 +0,0 @@
1
- require_relative "../lib/tty/logger"
2
-
3
- logger = TTY::Logger.new(fields: {app: "parent", env: "prod"})
4
- child_logger = logger.copy(app: "child") do |config|
5
- config.filters = ["logging"]
6
- end
7
-
8
- logger.info("Parent logging")
9
- child_logger.warn("Child logging")
data/examples/console.rb DELETED
@@ -1,22 +0,0 @@
1
- require_relative "../lib/tty/logger"
2
-
3
- TTY::Logger.configure do |config|
4
- # config.max_bytes = 2**5
5
- # config.metadata = [:all]
6
- # config.handlers = [[:console, formatter: :text]]
7
- config.level = :debug
8
- end
9
-
10
- logger = TTY::Logger.new(fields: {app: "myapp", env: "prod"})
11
-
12
- logger.copy(path: "/var/www/example.com").info("Deploying", "code")
13
-
14
- puts "Levels:"
15
-
16
- logger.debug("Debugging deployment")
17
- logger.info("Info about the deploy")
18
- logger.warn("Lack of resources")
19
- logger.error("Failed to deploy")
20
- logger.fatal("Terribly failed to deploy")
21
- logger.success("Deployed successfully")
22
- logger.wait("Ready to deploy")
@@ -1,27 +0,0 @@
1
- require_relative "../lib/tty/logger"
2
-
3
- logger = TTY::Logger.new do |config|
4
- config.types = {thanks: {level: :info}, done: {level: :info}}
5
- config.handlers = [
6
- [:console, {
7
- styles: {
8
- thanks: {
9
- symbol: "❤️ ",
10
- label: "thanks",
11
- color: :magenta,
12
- levelpad: 0
13
- },
14
- done: {
15
- symbol: "!!",
16
- label: "done",
17
- color: :green,
18
- levelpad: 2
19
- }
20
- }
21
- }]
22
- ]
23
- end
24
-
25
- logger.info("This is info!")
26
- logger.thanks("Great work!")
27
- logger.done("Work done!")
data/examples/error.rb DELETED
@@ -1,11 +0,0 @@
1
- require_relative "../lib/tty/logger"
2
-
3
- logger = TTY::Logger.new(fields: {app: "myapp", env: "prod"}) do |config|
4
- end
5
-
6
- begin
7
- raise ArgumentError, "Wrong data"
8
- rescue => ex
9
- error = ex
10
- logger.fatal("Error:", error)
11
- end
data/examples/handler.rb DELETED
@@ -1,19 +0,0 @@
1
- require_relative "../lib/tty/logger"
2
-
3
- class MyHandler
4
- def initialize(options = {})
5
- @name = options[:name]
6
- end
7
-
8
- def call(event)
9
- puts "(#{@name}) #{event.metadata[:name]} #{event.message}"
10
- end
11
- end
12
-
13
- TTY::Logger.configure do |config|
14
- config.handlers = [[MyHandler, {name: :hello}]]
15
- end
16
-
17
- logger = TTY::Logger.new
18
-
19
- logger.info("Custom logging")
data/examples/log.rb DELETED
@@ -1,9 +0,0 @@
1
- require_relative "../lib/tty/logger"
2
-
3
- logger = TTY::Logger.new do |config|
4
- config.level = :debug
5
- end
6
-
7
- def success
8
- logger.log(:debug, "Deploying...")
9
- end
data/examples/output.rb DELETED
@@ -1,15 +0,0 @@
1
- require_relative "../lib/tty/logger"
2
-
3
- file = File.open("errors.log", "a")
4
-
5
- TTY::Logger.configure do |config|
6
- config.metadata = [:all]
7
- config.handlers = [:stream]
8
- config.output = file
9
- end
10
-
11
- logger = TTY::Logger.new(fields: {app: "myapp", env: "prod"})
12
-
13
- logger.error("Failed to deploy")
14
-
15
- file.close
data/examples/override.rb DELETED
@@ -1,29 +0,0 @@
1
- require_relative "../lib/tty/logger"
2
-
3
- logger = TTY::Logger.new
4
-
5
- logger.success("Default success")
6
- logger.error("Default error")
7
-
8
- puts
9
-
10
- new_style = TTY::Logger.new do |config|
11
- config.handlers = [
12
- [:console, {
13
- styles: {
14
- success: {
15
- symbol: "+",
16
- label: "Ohh yes"
17
- },
18
- error: {
19
- symbol: "!",
20
- label: "Dooh",
21
- levelpad: 3
22
- }
23
- }
24
- }]
25
- ]
26
- end
27
-
28
- new_style.success("Custom success")
29
- new_style.error("Custom error")
data/examples/stream.rb DELETED
@@ -1,22 +0,0 @@
1
- require_relative "../lib/tty/logger"
2
-
3
- TTY::Logger.configure do |config|
4
- config.max_bytes = 2**7
5
- config.metadata = [:all]
6
- config.handlers = [[:stream, formatter: :text]]
7
- config.level = :debug
8
- end
9
-
10
- logger = TTY::Logger.new(fields: {app: "myapp", env: "prod"})
11
-
12
- logger.copy(path: "/var/www/example.com").info("Deploying", "code")
13
-
14
- puts "Levels:"
15
-
16
- logger.debug("Debugging deployment")
17
- logger.info("Info about the deploy")
18
- logger.warn("Lack of resources")
19
- logger.error("Failed to deploy")
20
- logger.fatal("Terribly failed to deploy")
21
- logger.success("Deployed successfully")
22
- logger.wait("Ready to deploy")
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rspec-benchmark"
4
-
5
- RSpec.describe TTY::Logger::Formatters::JSON do
6
- include RSpec::Benchmark::Matchers
7
-
8
- it "formats large hashes(2048 keys) 2x slower than the native JSON" do
9
- large_data = Hash[Array.new(2048) { |i| [i + 1, "hey"] }]
10
- formatter = described_class.new
11
-
12
- expect {
13
- formatter.dump(large_data)
14
- }.to perform_slower_than {
15
- ::JSON.dump(large_data)
16
- }.at_least(2).times
17
- end
18
-
19
- it "formats large values 2x slower than the native JSON" do
20
- large_data = { "foo" => "b#{'a'*2048}" }
21
- formatter = described_class.new
22
-
23
- expect {
24
- formatter.dump(large_data)
25
- }.to perform_slower_than {
26
- ::JSON.dump(large_data)
27
- }.at_least(2).times
28
- end
29
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rspec-benchmark"
4
- require "logger"
5
-
6
- RSpec.describe TTY::Logger do
7
- include RSpec::Benchmark::Matchers
8
-
9
- let(:output) { StringIO.new }
10
-
11
- it "performs 3x slower than native logger" do
12
- native_logger = Logger.new(output)
13
- logger = described_class.new(output: output)
14
-
15
- expect {
16
- logger.info("Deployment done!")
17
- }.to perform_slower_than {
18
- native_logger.info("Deployment done!")
19
- }.at_least(3).times
20
- end
21
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rspec-benchmark"
4
-
5
- RSpec.describe TTY::Logger::Formatters::Text do
6
- include RSpec::Benchmark::Matchers
7
-
8
- it "formats large hashes(2048 keys) 1.25x slower than the native JSON" do
9
- large_data = Hash[Array.new(2048) { |i| [i + 1, "hey"] }]
10
- formatter = described_class.new
11
-
12
- expect {
13
- formatter.dump(large_data)
14
- }.to perform_slower_than {
15
- ::JSON.dump(large_data)
16
- }.at_least(1.25).times
17
- end
18
-
19
- it "formats large values 4x slower than the native JSON" do
20
- large_data = { "foo" => "b#{'a'*2048}" }
21
- formatter = described_class.new
22
-
23
- expect {
24
- formatter.dump(large_data)
25
- }.to perform_slower_than {
26
- ::JSON.dump(large_data)
27
- }.at_least(4).times
28
- end
29
- end
data/spec/spec_helper.rb DELETED
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if ENV['COVERAGE'] || ENV['TRAVIS']
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ])
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require "bundler/setup"
19
- require "tty-logger"
20
-
21
- RSpec.configure do |config|
22
- # Enable flags like --only-failures and --next-failure
23
- config.example_status_persistence_file_path = ".rspec_status"
24
-
25
- # Disable RSpec exposing methods globally on `Module` and `main`
26
- config.disable_monkey_patching!
27
-
28
- config.expect_with :rspec do |c|
29
- c.syntax = :expect
30
- end
31
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Logger, "#add_handler" do
4
- let(:output) { StringIO.new }
5
- let(:styles) { TTY::Logger::Handlers::Console::STYLES }
6
-
7
- it "dynamically adds and removes a handler object" do
8
- logger = TTY::Logger.new(output: output) do |config|
9
- config.handlers = []
10
- end
11
-
12
- logger.info("No handler")
13
-
14
- logger.add_handler :console
15
-
16
- logger.info("Console handler")
17
-
18
- logger.remove_handler :console
19
-
20
- expect(output.string).to eq([
21
- "\e[32m#{styles[:info][:symbol]}\e[0m ",
22
- "\e[32minfo\e[0m ",
23
- "Console handler \n"].join)
24
- end
25
- end
@@ -1,109 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Logger::Config do
4
- let(:output) { StringIO.new }
5
- let(:styles) { TTY::Logger::Handlers::Console::STYLES }
6
-
7
- it "defaults :max_bytes to 8192" do
8
- config = described_class.new
9
- expect(config.max_bytes).to eq(8192)
10
- end
11
-
12
- it "defaults :max_depth to 3" do
13
- config = described_class.new
14
- expect(config.max_depth).to eq(3)
15
- end
16
-
17
- it "defaults :level to :info" do
18
- config = described_class.new
19
- expect(config.level).to eq(:info)
20
- end
21
-
22
- it "sets :max_bytes" do
23
- config = described_class.new
24
- config.max_bytes = 2**8
25
- expect(config.max_bytes).to eq(256)
26
- end
27
-
28
- it "defaults metadata to empty array" do
29
- config = described_class.new
30
- expect(config.metadata).to eq([])
31
- end
32
-
33
- it "defaults handlers to console" do
34
- config = described_class.new
35
- expect(config.handlers).to eq([:console])
36
- end
37
-
38
- it "defaults formatter to text" do
39
- config = described_class.new
40
- expect(config.formatter).to eq(:text)
41
- end
42
-
43
- it "defaults date format to %F" do
44
- config = described_class.new
45
- expect(config.date_format).to eq("%F")
46
- end
47
-
48
- it "defaults output to stderr" do
49
- config = described_class.new
50
- expect(config.output).to eq($stderr)
51
- end
52
-
53
- it "serializes data into hash" do
54
- config = described_class.new
55
- expect(config.to_h).to eq({
56
- date_format: "%F",
57
- formatter: :text,
58
- filters: {},
59
- handlers: [:console],
60
- level: :info,
61
- max_bytes: 8192,
62
- max_depth: 3,
63
- metadata: [],
64
- output: $stderr,
65
- time_format: "%T.%3N",
66
- types: {}
67
- })
68
- end
69
-
70
- it "yields configuration instance" do
71
- config = double(:config)
72
- allow(TTY::Logger).to receive(:config).and_return(config)
73
- expect { |block|
74
- TTY::Logger.configure(&block)
75
- }.to yield_with_args(config)
76
- end
77
-
78
- it "configures output size" do
79
- logger = TTY::Logger.new(output: output) do |config|
80
- config.max_bytes = 2**4
81
- config.level = :debug
82
- end
83
-
84
- logger.debug("Deploying", app: "myapp", env: "prod")
85
-
86
- expect(output.string).to eq([
87
- "\e[36m#{styles[:debug][:symbol]}\e[0m ",
88
- "\e[36mdebug\e[0m ",
89
- "Deploying ",
90
- "\e[36mapp\e[0m=myapp ...\n"
91
- ].join)
92
- end
93
-
94
- it "configures maximum depth of structured data" do
95
- logger = TTY::Logger.new(output: output) do |config|
96
- config.max_depth = 1
97
- config.level = :debug
98
- end
99
-
100
- logger.debug("Deploying", app: "myapp", env: { name: "prod" })
101
-
102
- expect(output.string).to eq([
103
- "\e[36m#{styles[:debug][:symbol]}\e[0m ",
104
- "\e[36mdebug\e[0m ",
105
- "Deploying ",
106
- "\e[36mapp\e[0m=myapp \e[36menv\e[0m={...}\n"
107
- ].join)
108
- end
109
- end