Class: TestaLogger::Logger
- Inherits:
-
Object
- Object
- TestaLogger::Logger
- Includes:
- Persistence
- Defined in:
- lib/testa_logger/logger.rb,
lib/testa_logger/logger/options.rb,
lib/testa_logger/logger/dispatcher.rb,
lib/testa_logger/logger/persistence.rb
Overview
noinspection RubyTooManyMethodsInspection
Defined Under Namespace
Modules: Persistence Classes: Dispatcher, Options
Constant Summary collapse
- TAG =
"TestaLogger"
- DEBUG =
Low-level information, mostly for developers.
0
- INFO =
Generic (useful) information about system operation.
1
- WARN =
A warning.
2
- ERROR =
A handleable error condition.
3
- FATAL =
An unhandleable error that results in a program crash.
4
- UNKNOWN =
An unknown message that should always be logged.
5
- NO_TAG =
"NO-TAG"
Instance Attribute Summary collapse
Instance Method Summary collapse
- #create_log_file ⇒ Object
- #debug(tag = nil, *args, &block) ⇒ Object
-
#debug! ⇒ Object
Sets the severity to DEBUG.
-
#debug? ⇒ Boolean
Returns
true
iff the current severity level allows for the printing ofDEBUG
messages. - #error(tag = nil, *args, &block) ⇒ Object
-
#error! ⇒ Object
Sets the severity to ERROR.
-
#error? ⇒ Boolean
Returns
true
iff the current severity level allows for the printing ofERROR
messages. - #fatal(tag = nil, *args, &block) ⇒ Object
-
#fatal! ⇒ Object
Sets the severity to FATAL.
-
#fatal? ⇒ Boolean
Returns
true
iff the current severity level allows for the printing ofFATAL
messages. - #formatter ⇒ Object
- #info(tag = nil, *args, &block) ⇒ Object
-
#info! ⇒ Object
Sets the severity to INFO.
-
#info? ⇒ Boolean
Returns
true
iff the current severity level allows for the printing ofINFO
messages. -
#initialize(app, group, subgroup = nil, options = {}) ⇒ Logger
constructor
A new instance of Logger.
- #level ⇒ Object
- #level=(severity) ⇒ Object
- #setup_dispatcher ⇒ Object
- #silence(severity = ERROR, &block) ⇒ Object
- #unknown(tag = nil, *args, &block) ⇒ Object
- #warn(tag = nil, *args, &block) ⇒ Object
-
#warn! ⇒ Object
Sets the severity to WARN.
-
#warn? ⇒ Boolean
Returns
true
iff the current severity level allows for the printing ofWARN
messages.
Methods included from Persistence
#init_s3_client, #persist, #persist_with_record
Constructor Details
#initialize(app, group, subgroup = nil, options = {}) ⇒ Logger
Returns a new instance of Logger.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/testa_logger/logger.rb', line 36 def initialize(app, group, subgroup = nil, = {}) @pause = false @pending_logs = [] @app = app @group = group @subgroup = subgroup @options = Options.new(app, group, subgroup, ) create_log_file setup_dispatcher init_s3_client if @options.persist end |
Instance Attribute Details
#app ⇒ String
13 14 15 |
# File 'lib/testa_logger/logger.rb', line 13 def app @app end |
#group ⇒ String
13 14 15 |
# File 'lib/testa_logger/logger.rb', line 13 def group @group end |
#subgroup ⇒ String
13 14 15 |
# File 'lib/testa_logger/logger.rb', line 13 def subgroup @subgroup end |
#write_thread ⇒ Thread
19 20 21 |
# File 'lib/testa_logger/logger.rb', line 19 def write_thread @write_thread end |
Instance Method Details
#create_log_file ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/testa_logger/logger.rb', line 49 def create_log_file .filepath = "/tmp/#{SecureRandom.uuid}.log" if .filepath.nil? FileUtils.mkdir_p(File.dirname(.filepath)) before_shift = .persist ? proc { persist } : nil @log_device = LogDevice.new(.filepath, shift_age: .shift_age, shift_size: 1_048_576, shift_period_suffix: "%d%m%Y", binmode: false, before_shift: before_shift) end |
#debug(tag = nil, *args, &block) ⇒ Object
73 74 75 |
# File 'lib/testa_logger/logger.rb', line 73 def debug(tag = nil, *args, &block) add(DEBUG, tag, args, &block) end |
#debug! ⇒ Object
Sets the severity to DEBUG.
112 113 114 |
# File 'lib/testa_logger/logger.rb', line 112 def debug! .level = DEBUG end |
#debug? ⇒ Boolean
Returns true
iff the current severity level allows for the printing of DEBUG
messages.
107 108 109 |
# File 'lib/testa_logger/logger.rb', line 107 def debug? .level <= DEBUG end |
#error(tag = nil, *args, &block) ⇒ Object
85 86 87 |
# File 'lib/testa_logger/logger.rb', line 85 def error(tag = nil, *args, &block) add(ERROR, tag, args, &block) end |
#error! ⇒ Object
Sets the severity to ERROR.
145 146 147 |
# File 'lib/testa_logger/logger.rb', line 145 def error! .level = ERROR end |
#error? ⇒ Boolean
Returns true
iff the current severity level allows for the printing of ERROR
messages.
140 141 142 |
# File 'lib/testa_logger/logger.rb', line 140 def error? .level <= ERROR end |
#fatal(tag = nil, *args, &block) ⇒ Object
89 90 91 |
# File 'lib/testa_logger/logger.rb', line 89 def fatal(tag = nil, *args, &block) add(FATAL, tag, args, &block) end |
#fatal! ⇒ Object
Sets the severity to FATAL.
156 157 158 |
# File 'lib/testa_logger/logger.rb', line 156 def fatal! .level = FATAL end |
#fatal? ⇒ Boolean
Returns true
iff the current severity level allows for the printing of FATAL
messages.
151 152 153 |
# File 'lib/testa_logger/logger.rb', line 151 def fatal? .level <= FATAL end |
#formatter ⇒ Object
69 70 71 |
# File 'lib/testa_logger/logger.rb', line 69 def formatter .formatter end |
#info(tag = nil, *args, &block) ⇒ Object
77 78 79 |
# File 'lib/testa_logger/logger.rb', line 77 def info(tag = nil, *args, &block) add(INFO, tag, args, &block) end |
#info! ⇒ Object
Sets the severity to INFO.
123 124 125 |
# File 'lib/testa_logger/logger.rb', line 123 def info! .level = INFO end |
#info? ⇒ Boolean
Returns true
iff the current severity level allows for the printing of INFO
messages.
118 119 120 |
# File 'lib/testa_logger/logger.rb', line 118 def info? .level <= INFO end |
#level ⇒ Object
160 161 162 |
# File 'lib/testa_logger/logger.rb', line 160 def level .level end |
#level=(severity) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/testa_logger/logger.rb', line 97 def level=(severity) if severity.is_a?(Integer) .level = severity else SEV_LABEL.index(severity.to_s.downcase.upcase).to_i end end |
#setup_dispatcher ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/testa_logger/logger.rb', line 61 def setup_dispatcher @dispatcher = Dispatcher.new( self, .faye_url, .faye_token ) end |
#silence(severity = ERROR, &block) ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/testa_logger/logger.rb', line 164 def silence(severity = ERROR, &block) old_level = .level .level = severity result = block&.call .level = old_level result end |
#unknown(tag = nil, *args, &block) ⇒ Object
93 94 95 |
# File 'lib/testa_logger/logger.rb', line 93 def unknown(tag = nil, *args, &block) add(UNKNOWN, tag, args, &block) end |
#warn(tag = nil, *args, &block) ⇒ Object
81 82 83 |
# File 'lib/testa_logger/logger.rb', line 81 def warn(tag = nil, *args, &block) add(WARN, tag, args, &block) end |
#warn! ⇒ Object
Sets the severity to WARN.
134 135 136 |
# File 'lib/testa_logger/logger.rb', line 134 def warn! .level = WARN end |
#warn? ⇒ Boolean
Returns true
iff the current severity level allows for the printing of WARN
messages.
129 130 131 |
# File 'lib/testa_logger/logger.rb', line 129 def warn? .level <= WARN end |