Class: Cosmos::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
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.
- .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.
-
#microservice_name ⇒ String
Microservice name.
-
#scope ⇒ String
Scope.
-
#stdout ⇒ Boolean
Whether to output the message to stdout.
-
#tag ⇒ String
Fluent tag.
- #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 80 81 |
# File 'lib/cosmos/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 @tag = @container_name + ".log" @mutex = Mutex.new @no_store = ENV['COSMOS_NO_STORE'] end |
Class Method Details
.debug(message = nil, scope: nil, user: nil, &block) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/cosmos/utilities/logger.rb', line 112 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
136 137 138 139 140 141 |
# File 'lib/cosmos/utilities/logger.rb', line 136 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
144 145 146 147 148 149 |
# File 'lib/cosmos/utilities/logger.rb', line 144 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
120 121 122 123 124 125 |
# File 'lib/cosmos/utilities/logger.rb', line 120 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.
152 153 154 155 156 157 158 159 |
# File 'lib/cosmos/utilities/logger.rb', line 152 def self.instance return @@instance if @@instance @@mutex.synchronize do @@instance ||= self.new end @@instance end |
.warn(message = nil, scope: nil, user: nil, &block) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/cosmos/utilities/logger.rb', line 128 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
87 88 89 |
# File 'lib/cosmos/utilities/logger.rb', line 87 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.
39 |
# File 'lib/cosmos/utilities/logger.rb', line 39 instance_attr_accessor :detail_string |
#error(message = nil, scope: @scope, user: nil, &block) ⇒ Object
102 103 104 |
# File 'lib/cosmos/utilities/logger.rb', line 102 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
107 108 109 |
# File 'lib/cosmos/utilities/logger.rb', line 107 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
92 93 94 |
# File 'lib/cosmos/utilities/logger.rb', line 92 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.
36 |
# File 'lib/cosmos/utilities/logger.rb', line 36 instance_attr_accessor :level |
#microservice_name ⇒ String
Returns Microservice name.
45 |
# File 'lib/cosmos/utilities/logger.rb', line 45 instance_attr_accessor :microservice_name |
#scope ⇒ String
Returns Scope.
48 |
# File 'lib/cosmos/utilities/logger.rb', line 48 instance_attr_accessor :scope |
#stdout ⇒ Boolean
Returns Whether to output the message to stdout.
33 |
# File 'lib/cosmos/utilities/logger.rb', line 33 instance_attr_accessor :stdout |
#tag ⇒ String
Returns Fluent tag.
42 |
# File 'lib/cosmos/utilities/logger.rb', line 42 instance_attr_accessor :tag |
#warn(message = nil, scope: @scope, user: nil, &block) ⇒ Object
97 98 99 |
# File 'lib/cosmos/utilities/logger.rb', line 97 def warn( = nil, scope: @scope, user: nil, &block) (WARN_SEVERITY_STRING, , scope: scope, user: user, &block) if @level <= WARN end |