Module: Skylight::Core::Util::Logging Private
- Included in:
- Config, GC, Instrumenter, Middleware, Probes::Excon::Middleware, Probes::Mongo::Subscriber, Sidekiq::ServerMiddleware, Subscriber, Trace
- Defined in:
- lib/skylight/core/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
- #log_env_prefix ⇒ 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.
104 105 106 107 108 109 110 |
# File 'lib/skylight/core/util/logging.rb', line 104 def config_for_logging if respond_to?(:config) config elsif is_a?(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.
69 70 71 |
# File 'lib/skylight/core/util/logging.rb', line 69 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.
87 88 89 90 |
# File 'lib/skylight/core/util/logging.rb', line 87 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`
100 101 102 |
# File 'lib/skylight/core/util/logging.rb', line 100 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.
75 76 77 |
# File 'lib/skylight/core/util/logging.rb', line 75 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.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/skylight/core/util/logging.rb', line 115 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, format(msg, *args) else logger.send level, msg end return else Kernel.warn "Invalid logger" end end # Fallback if (module_name = is_a?(Module) ? name : self.class.name) root_name = module_name.split("::").first.upcase msg.prepend("[#{root_name}] ") end puts format(msg, *args) 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.
26 27 28 |
# File 'lib/skylight/core/util/logging.rb', line 26 def log_context {} end |
#log_env_prefix ⇒ 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.
30 31 32 33 34 35 36 |
# File 'lib/skylight/core/util/logging.rb', line 30 def log_env_prefix if (c = config_for_logging) c.class.env_prefix else "SKYLIGHT_" end 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.
42 43 44 |
# File 'lib/skylight/core/util/logging.rb', line 42 def raise_on_error? !!ENV["#{log_env_prefix}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?.
62 63 64 65 |
# File 'lib/skylight/core/util/logging.rb', line 62 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?.
51 52 53 54 |
# File 'lib/skylight/core/util/logging.rb', line 51 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.
38 39 40 |
# File 'lib/skylight/core/util/logging.rb', line 38 def trace? !!ENV["#{log_env_prefix}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.
81 82 83 |
# File 'lib/skylight/core/util/logging.rb', line 81 def warn(msg, *args) log :warn, msg, *args end |