nexus_semantic_logger 1.7.2 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -1
- data/lib/nexus_semantic_logger/appender_filter.rb +41 -1
- data/lib/nexus_semantic_logger/application.rb +3 -1
- data/lib/nexus_semantic_logger/datadog_formatter.rb +4 -6
- data/lib/nexus_semantic_logger/extensions/action_dispatch/debug_exceptions.rb +2 -1
- data/lib/nexus_semantic_logger/version.rb +2 -2
- data/lib/nexus_semantic_logger.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f13512ab6f95abaa8a782f2718438d924eeca7dd1ae014c0f5419b14f0b13bfa
|
4
|
+
data.tar.gz: 54594c63bca42969a1639e1d6295f51a6b4faf5222e340c8dbd0e00a9e16390b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc42282551ce7a194ab0e4891296891cfb0520943f7c4ba383c259a90ef59d035aacdc756c11f5ab2d18d17175e655d919d6d46f50399c8c51bde831343801e1
|
7
|
+
data.tar.gz: b4e966ed8e476ede32c07cfb85e16ebfb00337d7b7ba8fb9989bae1f180a2f170349f78b617b5aeae2d0c4edacf2b16d77748e566db7e89967fb8004eea3c186
|
data/README.md
CHANGED
@@ -9,7 +9,44 @@ As well as providing a semantic logger, this gem handles datadog telemetry assoc
|
|
9
9
|
* logs
|
10
10
|
* traces
|
11
11
|
* metrics
|
12
|
-
|
12
|
+
* statsd is automatically attached to datadog runtime metrics and may also be used for custom metrics.
|
13
|
+
|
14
|
+
### Customise log level per logger
|
15
|
+
|
16
|
+
For example, to show debug logging for `MySubscriber` while having all other logs on info.
|
17
|
+
|
18
|
+
```
|
19
|
+
# The log level must be set to the lowest level which can be dynamically controlled.
|
20
|
+
LOG_LEVEL=DEBUG
|
21
|
+
# The default level for filtered logs.
|
22
|
+
LOG_NAMES_DEFAULT_LEVEL=INFO
|
23
|
+
# Per level overrides for filtered logs.
|
24
|
+
LOG_NAMES_DEBUG=MySubscriber
|
25
|
+
```
|
26
|
+
|
27
|
+
* Customised log names are available for each level e.g. `LOG_NAMES_TRACE`
|
28
|
+
* Log names are matched on prefix.
|
29
|
+
* Multiple log names are supported via comma separated values.
|
30
|
+
|
31
|
+
### Changing log level dynamically
|
32
|
+
|
33
|
+
The default level for filtered logs (`LOG_NAMES_DEFAULT_LEVEL`) may be changed on a running instance with the `WINCH`
|
34
|
+
signal. This cycles through the available levels `[trace debug info warn error fatal]`.
|
35
|
+
|
36
|
+
Note that you cannot dynamically enable a level lower than the `LOG_LEVEL`. Instead the env var must be adjusted and the
|
37
|
+
instance restarted.
|
38
|
+
|
39
|
+
Send signal: `pkill --signal WINCH --count --full "^puma.*"`
|
40
|
+
|
41
|
+
Instance output: `WINCH signal changed LOG_NAMES_DEFAULT_LEVEL from debug to info`
|
42
|
+
|
43
|
+
### Querying current log level
|
44
|
+
|
45
|
+
The `SYS` signal will print the levels used by the running instance.
|
46
|
+
|
47
|
+
Send signal: `pkill --signal SYS --count --full "^puma.*"`
|
48
|
+
|
49
|
+
Instance output: `SYS signal reports LOG_LEVEL=debug LOG_NAMES_DEFAULT_LEVEL=warn`
|
13
50
|
|
14
51
|
### Sending metrics
|
15
52
|
|
@@ -32,8 +32,12 @@ module NexusSemanticLogger
|
|
32
32
|
}
|
33
33
|
end
|
34
34
|
|
35
|
+
def self.env_level
|
36
|
+
@@level ||= ENV.fetch('LOG_LEVEL', Rails.application.config.log_level).downcase
|
37
|
+
end
|
38
|
+
|
35
39
|
def self.env_names_default_level
|
36
|
-
@@names_default_level ||= ENV.fetch('LOG_NAMES_DEFAULT_LEVEL', Rails.application.config.log_level)
|
40
|
+
@@names_default_level ||= ENV.fetch('LOG_NAMES_DEFAULT_LEVEL', Rails.application.config.log_level).downcase
|
37
41
|
end
|
38
42
|
|
39
43
|
def self.env_names_trace
|
@@ -61,6 +65,7 @@ module NexusSemanticLogger
|
|
61
65
|
end
|
62
66
|
|
63
67
|
def self.flush
|
68
|
+
@@level = nil
|
64
69
|
@@names_default_level = nil
|
65
70
|
@@names_trace = nil
|
66
71
|
@@names_debug = nil
|
@@ -73,5 +78,40 @@ module NexusSemanticLogger
|
|
73
78
|
def self.fetch_env_names(var)
|
74
79
|
ENV.fetch(var, '').split(',').to_set
|
75
80
|
end
|
81
|
+
|
82
|
+
# Change LOG_LEVEL and LOG_NAMES_DEFAULT_LEVEL on a running process by sending signals.
|
83
|
+
# Each signal rotates through the levels, wrapping around.
|
84
|
+
# Based on SemanticLogger.add_signal_handler.
|
85
|
+
# Note that USR1/USR2 are already used by puma. WINCH/SYS should be unused these days.
|
86
|
+
def self.add_signal_handler(log_names_level_signal = "WINCH", info_signal = "SYS")
|
87
|
+
if log_names_level_signal
|
88
|
+
Signal.trap(log_names_level_signal) do
|
89
|
+
current_level = env_names_default_level
|
90
|
+
next_level = get_next_log_level(current_level)
|
91
|
+
@@names_default_level = next_level
|
92
|
+
puts "#{log_names_level_signal} signal changed LOG_NAMES_DEFAULT_LEVEL from #{current_level} to #{next_level}"
|
93
|
+
rescue => err
|
94
|
+
puts "Error handling signal #{log_names_level_signal}: #{err}"
|
95
|
+
puts err.backtrace
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
if info_signal
|
100
|
+
Signal.trap(info_signal) do
|
101
|
+
current_level = env_names_default_level
|
102
|
+
puts "#{info_signal} signal reports LOG_LEVEL=#{env_level} LOG_NAMES_DEFAULT_LEVEL=#{current_level}"
|
103
|
+
rescue => err
|
104
|
+
puts "Error handling signal #{info_signal}: #{err}"
|
105
|
+
puts err.backtrace
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.get_next_log_level(current_log_level)
|
111
|
+
current_log_level_index = SemanticLogger::Levels.index(current_log_level)
|
112
|
+
next_log_level_index = current_log_level_index + 1
|
113
|
+
next_log_level_index = 0 if next_log_level_index >= SemanticLogger::Levels.all_levels.size
|
114
|
+
SemanticLogger::Levels.level(next_log_level_index)
|
115
|
+
end
|
76
116
|
end
|
77
117
|
end
|
@@ -35,13 +35,15 @@ module NexusSemanticLogger
|
|
35
35
|
config.rails_semantic_logger.add_file_appender = false
|
36
36
|
dd_appender = config.semantic_logger.add_appender(io: $stdout, formatter: config.rails_semantic_logger.format)
|
37
37
|
dd_appender.filter = NexusSemanticLogger::AppenderFilter.filter_lambda
|
38
|
+
NexusSemanticLogger::AppenderFilter.add_signal_handler
|
38
39
|
|
39
40
|
NexusSemanticLogger::DatadogTracer.new(service)
|
40
41
|
|
41
42
|
logger.info('SemanticLogger initialised.', level: config.log_level)
|
42
43
|
|
43
44
|
config.after_initialize do
|
44
|
-
require("nexus_semantic_logger/extensions/action_dispatch/debug_exceptions") if defined?(
|
45
|
+
require("nexus_semantic_logger/extensions/action_dispatch/debug_exceptions") if defined?(
|
46
|
+
::ActionDispatch::DebugExceptions)
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
@@ -42,12 +42,10 @@ module NexusSemanticLogger
|
|
42
42
|
rescue SystemStackError
|
43
43
|
as_json_serialise_errors = []
|
44
44
|
hash.keys.each do |key|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
as_json_serialise_errors << key
|
50
|
-
end
|
45
|
+
hash[key].as_json
|
46
|
+
rescue SystemStackError
|
47
|
+
hash.delete(key)
|
48
|
+
as_json_serialise_errors << key
|
51
49
|
end
|
52
50
|
hash[:as_json_serialise_errors] = as_json_serialise_errors
|
53
51
|
hash.to_json
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module NexusSemanticLogger
|
3
|
-
# Leave this as 1.
|
4
|
-
VERSION = '1.
|
3
|
+
# Leave this as 1.8.0 in order for CI process to replace with the tagged version.
|
4
|
+
VERSION = '1.8.0'
|
5
5
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexus_semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johnathon Harris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|