Module: Skylight::Util::Logging Private
- Included in:
- Skylight, Api, Api::ConfigValidationResults, Config, Extensions::SourceLocation, GC, Instrumenter, Middleware, Normalizers::Normalizer, Probes::Mongo::Subscriber, Sidekiq::ServerMiddleware, Subscriber, Trace, Deploy::DefaultDeploy, HTTP
- Defined in:
- lib/skylight/util/logging.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #config_for_logging ⇒ Object private
- #debug(msg, *args) ⇒ Object (also: #log_debug) private
- #error(msg, *args) ⇒ Object (also: #log_error) private
-
#fmt(*args) ⇒ String
private
Alias for ‘Kernel#sprintf`.
- #info(msg, *args) ⇒ Object (also: #log_info) private
- #log(level, msg, *args) ⇒ Object private
- #log_context ⇒ Object private
- #raise_on_error? ⇒ Boolean private
-
#t { ... } ⇒ Object
private
Evaluates and logs the result of the block if tracing.
-
#trace(msg, *args) ⇒ Object
(also: #log_trace)
private
Logs if tracing.
- #trace? ⇒ Boolean private
- #warn(msg, *args) ⇒ Object (also: #log_warn) private
Instance Method Details
#config_for_logging ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
97 98 99 100 101 102 103 |
# File 'lib/skylight/util/logging.rb', line 97 def config_for_logging if respond_to?(:config) config elsif is_a?(Skylight::Config) self end end |
#debug(msg, *args) ⇒ Object Also known as: log_debug
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 |
# File 'lib/skylight/util/logging.rb', line 62 def debug(msg, *args) log :debug, msg, *args end |
#error(msg, *args) ⇒ Object Also known as: log_error
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 83 |
# File 'lib/skylight/util/logging.rb', line 80 def error(msg, *args) log :error, msg, *args raise format(msg, *args) if raise_on_error? end |
#fmt(*args) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Alias for ‘Kernel#sprintf`
93 94 95 |
# File 'lib/skylight/util/logging.rb', line 93 def fmt(*args) sprintf(*args) end |
#info(msg, *args) ⇒ Object Also known as: log_info
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/skylight/util/logging.rb', line 68 def info(msg, *args) log :info, msg, *args end |
#log(level, msg, *args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/skylight/util/logging.rb', line 108 def log(level, msg, *args) c = config_for_logging logger = c ? c.logger : nil msg = log_context.map { |(k, v)| "#{k}=#{v}; " }.join << msg if logger if logger.respond_to?(level) if args.empty? logger.send level, msg else logger.send level, format(msg, *args) end return # rubocop:disable Style/RedundantReturn else Kernel.warn "Invalid logger" end # Fallback to stderr for warn and error levels elsif %i[warn error].include?(level) $stderr.puts format("[SKYLIGHT] #{msg}", *args) end rescue Exception => e if trace? puts "[ERROR] #{e.}" puts e.backtrace end end |
#log_context ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 |
# File 'lib/skylight/util/logging.rb', line 25 def log_context {} end |
#raise_on_error? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/skylight/util/logging.rb', line 33 def raise_on_error? !!ENV[-"SKYLIGHT_RAISE_ON_ERROR"] end |
#t { ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Evaluates and logs the result of the block if tracing
See #trace?.
54 55 56 57 58 |
# File 'lib/skylight/util/logging.rb', line 54 def t return unless trace? log :debug, yield end |
#trace(msg, *args) ⇒ Object Also known as: log_trace
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Logs if tracing
See #trace?.
42 43 44 45 46 |
# File 'lib/skylight/util/logging.rb', line 42 def trace(msg, *args) return unless trace? log :debug, msg, *args end |
#trace? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 |
# File 'lib/skylight/util/logging.rb', line 29 def trace? !!ENV[-"SKYLIGHT_ENABLE_TRACE_LOGS"] end |
#warn(msg, *args) ⇒ Object Also known as: log_warn
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 |
# File 'lib/skylight/util/logging.rb', line 74 def warn(msg, *args) log :warn, msg, *args end |