Class: Logify::Logger
- Inherits:
-
Object
- Object
- Logify::Logger
- Defined in:
- lib/logify/logger.rb
Constant Summary collapse
- ANONYMOUS =
'(Anonymous)'
- 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) ⇒ true
Write a new debug message to the current IO object.
-
#error(message = nil, &block) ⇒ true
Write a new error message to the current IO object.
-
#fatal(message = nil, &block) ⇒ true
Write a new fatal message to the current IO object.
-
#info(message = nil, &block) ⇒ true
Write a new info message to the current IO object.
-
#initialize(id) ⇒ Logger
constructor
Create a new logger object.
-
#warn(message = nil, &block) ⇒ true
Write a new warn message to the current IO object.
Constructor Details
#initialize(id) ⇒ Logger
Create a new logger object.
103 104 105 |
# File 'lib/logify/logger.rb', line 103 def initialize(id) @id = id end |
Class Method Details
.level(name) ⇒ Object
26 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 |
# File 'lib/logify/logger.rb', line 26 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 << message if message buffer << yield if block_given? buffer << "#{NEWLINE}" MONITOR.synchronize { Logify.io.write(buffer) } true end end EOH end |
Instance Method Details
#debug(message = nil, &block) ⇒ true
Write a new debug message to the current IO object.
95 |
# File 'lib/logify/logger.rb', line 95 level :debug |
#error(message = nil, &block) ⇒ true
Write a new error message to the current IO object.
92 |
# File 'lib/logify/logger.rb', line 92 level :error |
#fatal(message = nil, &block) ⇒ true
Write a new fatal message to the current IO object.
91 |
# File 'lib/logify/logger.rb', line 91 level :fatal |
#info(message = nil, &block) ⇒ true
Write a new info message to the current IO object.
94 |
# File 'lib/logify/logger.rb', line 94 level :info |
#warn(message = nil, &block) ⇒ true
Write a new warn message to the current IO object.
93 |
# File 'lib/logify/logger.rb', line 93 level :warn |