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.
106 107 108 109 110 111 112 |
# File 'lib/skylight/core/util/logging.rb', line 106 def config_for_logging if respond_to?(:config) config elsif self.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.
71 72 73 |
# File 'lib/skylight/core/util/logging.rb', line 71 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.
89 90 91 92 |
# File 'lib/skylight/core/util/logging.rb', line 89 def error(msg, *args) log :error, msg, *args raise sprintf(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`
102 103 104 |
# File 'lib/skylight/core/util/logging.rb', line 102 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.
77 78 79 |
# File 'lib/skylight/core/util/logging.rb', line 77 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.
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 146 147 |
# File 'lib/skylight/core/util/logging.rb', line 117 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.length > 0 logger.send level, sprintf(msg, *args) else logger.send level, msg end return else Kernel.warn "Invalid logger" end end # Fallback if module_name = self.is_a?(Module) ? name : self.class.name root_name = module_name.split('::').first.upcase msg.prepend("[#{root_name}] ") end puts sprintf(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.
28 29 30 |
# File 'lib/skylight/core/util/logging.rb', line 28 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.
32 33 34 35 36 37 38 |
# File 'lib/skylight/core/util/logging.rb', line 32 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.
44 45 46 |
# File 'lib/skylight/core/util/logging.rb', line 44 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?.
64 65 66 67 |
# File 'lib/skylight/core/util/logging.rb', line 64 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?.
53 54 55 56 |
# File 'lib/skylight/core/util/logging.rb', line 53 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.
40 41 42 |
# File 'lib/skylight/core/util/logging.rb', line 40 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.
83 84 85 |
# File 'lib/skylight/core/util/logging.rb', line 83 def warn(msg, *args) log :warn, msg, *args end |