Class: Logify::Logger
- Inherits:
-
Object
- Object
- Logify::Logger
- Defined in:
- lib/logify/logger.rb
Constant Summary collapse
- ANONYMOUS =
'(Anonymous)'- FILTERED =
'[FILTERED]'- MAX_LENGTH =
32- NEWLINE =
"\n"- SEPARATOR =
' | '- MONITOR =
Monitor.new
- NONE =
5- FATAL =
4- ERROR =
3- WARN =
2- INFO =
1- DEBUG =
0- DEFAULT =
WARN- LEVEL_MAP =
{ none: NONE, fatal: FATAL, error: ERROR, warn: WARN, info: INFO, debug: DEBUG, }.freeze
- PREFIX_FATAL =
'F: '- PREFIX_ERROR =
'E: '- PREFIX_WARN =
'W: '- PREFIX_INFO =
'I: '- PREFIX_DEBUG =
'D: '- PREFIX_LONG_FATAL =
'!!!! '- PREFIX_LONG_ERROR =
'>>>> '- PREFIX_LONG_WARN =
'**** '- PREFIX_LONG_INFO =
'===> '- PREFIX_LONG_DEBUG =
' '
Class Method Summary collapse
Instance Method Summary collapse
-
#debug(message = nil, &block) ⇒ String
Write a new debug message to the current IO object.
-
#error(message = nil, &block) ⇒ String
Write a new error message to the current IO object.
-
#fatal(message = nil, &block) ⇒ String
Write a new fatal message to the current IO object.
-
#info(message = nil, &block) ⇒ String
Write a new info message to the current IO object.
-
#initialize(id) ⇒ Logger
constructor
Create a new logger object.
-
#warn(message = nil, &block) ⇒ String
Write a new warn message to the current IO object.
Constructor Details
#initialize(id) ⇒ Logger
Create a new logger object.
105 106 107 |
# File 'lib/logify/logger.rb', line 105 def initialize(id) @id = id end |
Class Method Details
.level(name) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/logify/logger.rb', line 27 def level(name) constant = name.to_s.upcase class_eval <<-EOH, __FILE__, __LINE__ + 1 def #{name}(message = nil, &block) if Logify.level <= #{constant} buffer = '' if Logify.level == #{DEBUG} buffer << formatted_id buffer << SEPARATOR buffer << PREFIX_LONG_#{constant} else buffer << PREFIX_#{constant} end buffer << filter(message) if message buffer << filter(yield) if block_given? buffer << "#{NEWLINE}" MONITOR.synchronize { Logify.io.write(buffer) } buffer end end EOH end |
Instance Method Details
#debug(message = nil, &block) ⇒ String
Write a new debug message to the current IO object.
97 |
# File 'lib/logify/logger.rb', line 97 level :debug |
#error(message = nil, &block) ⇒ String
Write a new error message to the current IO object.
94 |
# File 'lib/logify/logger.rb', line 94 level :error |
#fatal(message = nil, &block) ⇒ String
Write a new fatal message to the current IO object.
93 |
# File 'lib/logify/logger.rb', line 93 level :fatal |
#info(message = nil, &block) ⇒ String
Write a new info message to the current IO object.
96 |
# File 'lib/logify/logger.rb', line 96 level :info |
#warn(message = nil, &block) ⇒ String
Write a new warn message to the current IO object.
95 |
# File 'lib/logify/logger.rb', line 95 level :warn |