logrb 0.1.2 → 0.1.4

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
  SHA256:
3
- metadata.gz: d2b3538c59ff3cd6964b1322b178ff41acd4a61f9cba41eb32f57433d9ccafa3
4
- data.tar.gz: '0240916d10cc49d29214015d73d729eff14c72829212b86e57f17ea10be4395d'
3
+ metadata.gz: 7a53a6bde1d9ab431f87ad880a69ba3a44f8d0f2e30f130863a960d559b95365
4
+ data.tar.gz: 1f061d4e844f14e2128bd019fc16c258c23d7fd2d69e9e91631142828ea28274
5
5
  SHA512:
6
- metadata.gz: c552d0a05a75e68885c9a401d17350cabc4a7257e8bf0016083567fa59992a243764ae017daddeaa9b5312f59e40726fb5742223ea67b058bb935454458a486e
7
- data.tar.gz: 6c28c536a1afdd1eda0395ed6683127633e8d6701a39fb73294bc4a342aff5dc857f08c332aac0339a2e68d386e86d07d57ec76b04a083d2e18fa8f15c1c57b2
6
+ metadata.gz: 7a52eb0fa69cee37648bc2561acbcea29baab332a1228bfa94565d42c144ea5051c1125ee5d78a359f5df7f9de7e2bbad994bf6f65cac6865ce8d906dcccec0b
7
+ data.tar.gz: 71b8c09cd884198abc910854cb7919f5e3c15b82f61c6fcd36ce14ab55c016e40c324ca04f7f986574c3315cbc7c75e7e83d5f9f1cf15c05c8100f9f5686b5ab
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- logrb (0.1.2)
4
+ logrb (0.1.4)
5
5
  hexdump (~> 0.3.0)
6
6
 
7
7
  GEM
@@ -45,6 +45,7 @@ GEM
45
45
  unicode-display_width (2.0.0)
46
46
 
47
47
  PLATFORMS
48
+ arm64-darwin-23
48
49
  x86_64-darwin-20
49
50
  x86_64-linux
50
51
 
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Victor Gama
3
+ Copyright (c) 2021-2024 Vito Sartori
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/lib/logrb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Logrb
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/logrb.rb CHANGED
@@ -25,8 +25,11 @@ require "json"
25
25
  # current process to exit with a status 1.
26
26
  #
27
27
  # #warn(msg, **fields): Outputs a warning entry.
28
+ #
28
29
  # #info(msg, **fields): Outputs a informational entry.
30
+ #
29
31
  # #debug(msg, **fields): Outputs a debug entry.
32
+ #
30
33
  # #dump(msg, data=nil): Outputs a given String or Array of bytes using the
31
34
  # same format as `hexdump -C`.
32
35
  class Logrb
@@ -88,7 +91,7 @@ class Logrb
88
91
  inst
89
92
  end
90
93
 
91
- LEVELS.except(:error).each_key do |name|
94
+ LEVELS.except(:error, :fatal).each_key do |name|
92
95
  define_method(name) do |msg, **fields|
93
96
  return if LEVELS[@level] > LEVELS[name]
94
97
 
@@ -106,6 +109,15 @@ class Logrb
106
109
  nil
107
110
  end
108
111
 
112
+ # Public: Emits a fatal message to the log output, and invokes Kernel#exit
113
+ # with a non-zero status code. When error is provided, this method attempts
114
+ # to gather a stacktrace to include in the emitted entry. This log entry
115
+ # cannot be filtered, and is always emitted.
116
+ def fatal(msg, error = nil, **fields)
117
+ wrap(:fatal, msg, error, fields)
118
+ exit 1
119
+ end
120
+
109
121
  # Public: Dumps a given String or Array in the same format as `hexdump -C`.
110
122
  def dump(log, data = nil, **fields)
111
123
  return if LEVELS[@level] > LEVELS[:debug]
@@ -160,9 +172,9 @@ class Logrb
160
172
 
161
173
  # Internal: Performs a cleanup for a given backtrace frame.
162
174
  #
163
- # trace - Trace to be clean.
175
+ # trace - Trace to be clean.
164
176
  # include_function_name - Optional. When true, includes the function name
165
- # on the normalized string. Defaults to false.
177
+ # on the normalized string. Defaults to false.
166
178
  def normalize_location(trace, include_function_name: false)
167
179
  path = trace.absolute_path
168
180
  return trace.to_s if path.nil?
@@ -180,6 +192,7 @@ class Logrb
180
192
  end
181
193
 
182
194
  # Internal: Composes a log line with given information.
195
+ #
183
196
  # level - The severity of the log message
184
197
  # caller_meta - An Array containing the caller's location and name
185
198
  # msg - The message to be logged
@@ -197,6 +210,7 @@ class Logrb
197
210
  end
198
211
 
199
212
  # Internal: Logs a text entry to the current output.
213
+ #
200
214
  # level - The severity of the message to be logged.
201
215
  # msg - The message to be logged
202
216
  # error - Either an Exception object or nil. This parameter is used
@@ -241,6 +255,7 @@ class Logrb
241
255
  end
242
256
 
243
257
  # Internal: Logs a JSON entry to the current output.
258
+ #
244
259
  # level - The severity of the message to be logged.
245
260
  # msg - The message to be logged
246
261
  # error - Either an Exception object or nil. This parameter is used
@@ -258,7 +273,10 @@ class Logrb
258
273
  ts: Time.now.utc.to_i
259
274
  }
260
275
 
261
- data[:stacktrace] = backtrace(error) if level == :error
276
+ if level == :error
277
+ data[:exception] = error.message if error.respond_to?(:message)
278
+ data[:stacktrace] = backtrace(error)
279
+ end
262
280
 
263
281
  data.merge!(fields)
264
282
  write_output("#{data.to_json}\n")
data/logrb.gemspec CHANGED
@@ -5,7 +5,7 @@ require_relative "lib/logrb/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "logrb"
7
7
  spec.version = Logrb::VERSION
8
- spec.authors = ["Victor Gama"]
8
+ spec.authors = ["Vito Sartori"]
9
9
  spec.email = ["hey@vito.io"]
10
10
 
11
11
  spec.summary = "Small logger inspired by Go's Zap"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
- - Victor Gama
7
+ - Vito Sartori
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-16 00:00:00.000000000 Z
11
+ date: 2024-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hexdump
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.2.22
71
+ rubygems_version: 3.4.10
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: Small logger inspired by Go's Zap