Class: OpenC3::Logger
Overview
Supports different levels of logging and only writes if the level is exceeded.
Constant Summary collapse
- DEBUG =
DEBUG only prints DEBUG messages
::Logger::DEBUG
- INFO =
INFO prints INFO, DEBUG messages
::Logger::INFO
- WARN =
WARN prints WARN, INFO, DEBUG messages
::Logger::WARN
- ERROR =
ERROR prints ERROR, WARN, INFO, DEBUG messages
::Logger::ERROR
- FATAL =
FATAL prints FATAL, ERROR, WARN, INFO, DEBUG messages
::Logger::FATAL
- DEBUG_SEVERITY_STRING =
'DEBUG'
- INFO_SEVERITY_STRING =
'INFO'
- WARN_SEVERITY_STRING =
'WARN'
- ERROR_SEVERITY_STRING =
'ERROR'
- FATAL_SEVERITY_STRING =
'FATAL'
- @@mutex =
Mutex.new
- @@instance =
nil
Instance Attribute Summary collapse
-
#microservice_name ⇒ String
Microservice name.
Class Method Summary collapse
- .debug(message = nil, scope: nil, user: nil, &block) ⇒ Object
- .error(message = nil, scope: nil, user: nil, &block) ⇒ Object
- .fatal(message = nil, scope: nil, user: nil, &block) ⇒ Object
- .info(message = nil, scope: nil, user: nil, &block) ⇒ Object
-
.instance ⇒ Logger
The logger instance.
- .microservice_name ⇒ Object
- .microservice_name=(name) ⇒ Object
- .warn(message = nil, scope: nil, user: nil, &block) ⇒ Object
Instance Method Summary collapse
- #debug(message = nil, scope: @scope, user: nil, &block) ⇒ Object
-
#detail_string ⇒ String
Additional detail to add to messages.
- #error(message = nil, scope: @scope, user: nil, &block) ⇒ Object
- #fatal(message = nil, scope: @scope, user: nil, &block) ⇒ Object
- #info(message = nil, scope: @scope, user: nil, &block) ⇒ Object
-
#initialize(level = Logger::INFO) ⇒ Logger
constructor
A new instance of Logger.
-
#level ⇒ Integer
The logging level.
-
#scope ⇒ String
Scope.
-
#stdout ⇒ Boolean
Whether to output the message to stdout.
- #warn(message = nil, scope: @scope, user: nil, &block) ⇒ Object
Constructor Details
#initialize(level = Logger::INFO) ⇒ Logger
Returns a new instance of Logger.
71 72 73 74 75 76 77 78 79 |
# File 'lib/openc3/utilities/logger.rb', line 71 def initialize(level = Logger::INFO) @stdout = true @level = level @scope = nil @detail_string = nil @container_name = Socket.gethostname @microservice_name = nil @no_store = ENV['OPENC3_NO_STORE'] end |
Instance Attribute Details
#microservice_name ⇒ String
Returns Microservice name.
45 46 47 |
# File 'lib/openc3/utilities/logger.rb', line 45 def microservice_name @microservice_name end |
Class Method Details
.debug(message = nil, scope: nil, user: nil, &block) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/openc3/utilities/logger.rb', line 123 def self.debug( = nil, scope: nil, user: nil, &block) args = {} args[:scope] = scope if scope args[:user] = user if user self.instance.debug(, **args, &block) end |
.error(message = nil, scope: nil, user: nil, &block) ⇒ Object
147 148 149 150 151 152 |
# File 'lib/openc3/utilities/logger.rb', line 147 def self.error( = nil, scope: nil, user: nil, &block) args = {} args[:scope] = scope if scope args[:user] = user if user self.instance.error(, **args, &block) end |
.fatal(message = nil, scope: nil, user: nil, &block) ⇒ Object
155 156 157 158 159 160 |
# File 'lib/openc3/utilities/logger.rb', line 155 def self.fatal( = nil, scope: nil, user: nil, &block) args = {} args[:scope] = scope if scope args[:user] = user if user self.instance.fatal(, **args, &block) end |
.info(message = nil, scope: nil, user: nil, &block) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/openc3/utilities/logger.rb', line 131 def self.info( = nil, scope: nil, user: nil, &block) args = {} args[:scope] = scope if scope args[:user] = user if user self.instance.info(, **args, &block) end |
.instance ⇒ Logger
Returns The logger instance.
163 164 165 166 167 168 169 170 |
# File 'lib/openc3/utilities/logger.rb', line 163 def self.instance return @@instance if @@instance @@mutex.synchronize do @@instance ||= self.new end @@instance end |
.microservice_name ⇒ Object
86 87 88 |
# File 'lib/openc3/utilities/logger.rb', line 86 def self.microservice_name self.instance.microservice_name end |
.microservice_name=(name) ⇒ Object
90 91 92 |
# File 'lib/openc3/utilities/logger.rb', line 90 def self.microservice_name=(name) self.instance.microservice_name = name end |
.warn(message = nil, scope: nil, user: nil, &block) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/openc3/utilities/logger.rb', line 139 def self.warn( = nil, scope: nil, user: nil, &block) args = {} args[:scope] = scope if scope args[:user] = user if user self.instance.warn(, **args, &block) end |
Instance Method Details
#debug(message = nil, scope: @scope, user: nil, &block) ⇒ Object
98 99 100 |
# File 'lib/openc3/utilities/logger.rb', line 98 def debug( = nil, scope: @scope, user: nil, &block) (DEBUG_SEVERITY_STRING, , scope: scope, user: user, &block) if @level <= DEBUG end |
#detail_string ⇒ String
Returns Additional detail to add to messages.
42 |
# File 'lib/openc3/utilities/logger.rb', line 42 instance_attr_accessor :detail_string |
#error(message = nil, scope: @scope, user: nil, &block) ⇒ Object
113 114 115 |
# File 'lib/openc3/utilities/logger.rb', line 113 def error( = nil, scope: @scope, user: nil, &block) (ERROR_SEVERITY_STRING, , scope: scope, user: user, &block) if @level <= ERROR end |
#fatal(message = nil, scope: @scope, user: nil, &block) ⇒ Object
118 119 120 |
# File 'lib/openc3/utilities/logger.rb', line 118 def fatal( = nil, scope: @scope, user: nil, &block) (FATAL_SEVERITY_STRING, , scope: scope, user: user, &block) if @level <= FATAL end |
#info(message = nil, scope: @scope, user: nil, &block) ⇒ Object
103 104 105 |
# File 'lib/openc3/utilities/logger.rb', line 103 def info( = nil, scope: @scope, user: nil, &block) (INFO_SEVERITY_STRING, , scope: scope, user: user, &block) if @level <= INFO end |
#level ⇒ Integer
Returns The logging level.
39 |
# File 'lib/openc3/utilities/logger.rb', line 39 instance_attr_accessor :level |
#scope ⇒ String
Returns Scope.
48 |
# File 'lib/openc3/utilities/logger.rb', line 48 instance_attr_accessor :scope |
#stdout ⇒ Boolean
Returns Whether to output the message to stdout.
36 |
# File 'lib/openc3/utilities/logger.rb', line 36 instance_attr_accessor :stdout |
#warn(message = nil, scope: @scope, user: nil, &block) ⇒ Object
108 109 110 |
# File 'lib/openc3/utilities/logger.rb', line 108 def warn( = nil, scope: @scope, user: nil, &block) (WARN_SEVERITY_STRING, , scope: scope, user: user, &block) if @level <= WARN end |