Class: Redis::DistributedLogger
- Inherits:
-
Object
- Object
- Redis::DistributedLogger
- Defined in:
- lib/redis/distributed_logger.rb,
lib/redis/distributed_logger/version.rb
Constant Summary collapse
- 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
- VERSION =
"1.0.1"
Instance Attribute Summary collapse
-
#datetime_format ⇒ Object
for compatibily with classic Logger methods.
-
#level ⇒ Object
for compatibily with classic Logger methods.
Instance Method Summary collapse
- #<<(msg) ⇒ Object
- #add(severity, message = nil, progname = nil, &block) ⇒ Object (also: #log)
- #close ⇒ Object
- #debug(arg = nil, &block) ⇒ Object
- #debug? ⇒ Boolean
- #error(arg = nil, &block) ⇒ Object
- #error? ⇒ Boolean
- #fatal(arg = nil, &block) ⇒ Object
- #fatal? ⇒ Boolean
- #info(arg = nil, &block) ⇒ Object
- #info? ⇒ Boolean
-
#initialize(redis, key, stdout = nil) ⇒ DistributedLogger
constructor
A new instance of DistributedLogger.
- #unknown(arg = nil, &block) ⇒ Object
- #warn(arg = nil, &block) ⇒ Object
- #warn? ⇒ Boolean
Constructor Details
#initialize(redis, key, stdout = nil) ⇒ DistributedLogger
Returns a new instance of DistributedLogger.
22 23 24 25 26 27 |
# File 'lib/redis/distributed_logger.rb', line 22 def initialize( redis, key, stdout = nil ) @_redis = redis @_key = key @_stdout = stdout @_level = INFO end |
Instance Attribute Details
#datetime_format ⇒ Object
for compatibily with classic Logger methods
20 21 22 |
# File 'lib/redis/distributed_logger.rb', line 20 def datetime_format @datetime_format end |
#level ⇒ Object
for compatibily with classic Logger methods
20 21 22 |
# File 'lib/redis/distributed_logger.rb', line 20 def level @level end |
Instance Method Details
#<<(msg) ⇒ Object
29 30 31 |
# File 'lib/redis/distributed_logger.rb', line 29 def <<(msg) @_redis.lpush( @_key, { at: Time.now.to_i, severity: nil, progname: nil, message: msg }.to_json ) end |
#add(severity, message = nil, progname = nil, &block) ⇒ Object Also known as: log
33 34 35 |
# File 'lib/redis/distributed_logger.rb', line 33 def add( severity, = nil, progname = nil, &block ) @_redis.lpush( @_key, { at: Time.now.to_i, severity: severity, progname: block_given? ? : progname, message: block_given? ? yield : }.to_json ) end |
#close ⇒ Object
38 39 40 |
# File 'lib/redis/distributed_logger.rb', line 38 def close # nothing end |
#debug(arg = nil, &block) ⇒ Object
62 63 64 |
# File 'lib/redis/distributed_logger.rb', line 62 def debug( arg = nil, &block ) add( DEBUG, block_given? ? yield : arg, block_given? ? arg : nil ) end |
#debug? ⇒ Boolean
42 43 44 |
# File 'lib/redis/distributed_logger.rb', line 42 def debug? @_level <= DEBUG end |
#error(arg = nil, &block) ⇒ Object
66 67 68 |
# File 'lib/redis/distributed_logger.rb', line 66 def error( arg = nil, &block ) add( ERROR, block_given? ? yield : arg, block_given? ? arg : nil ) end |
#error? ⇒ Boolean
46 47 48 |
# File 'lib/redis/distributed_logger.rb', line 46 def error? @_level <= ERROR end |
#fatal(arg = nil, &block) ⇒ Object
70 71 72 |
# File 'lib/redis/distributed_logger.rb', line 70 def fatal( arg = nil, &block ) add( FATAL, block_given? ? yield : arg, block_given? ? arg : nil ) end |
#fatal? ⇒ Boolean
50 51 52 |
# File 'lib/redis/distributed_logger.rb', line 50 def fatal? @_level <= FATAL end |
#info(arg = nil, &block) ⇒ Object
74 75 76 |
# File 'lib/redis/distributed_logger.rb', line 74 def info( arg = nil, &block ) add( INFO, block_given? ? yield : arg, block_given? ? arg : nil ) end |
#info? ⇒ Boolean
54 55 56 |
# File 'lib/redis/distributed_logger.rb', line 54 def info? @_level <= INFO end |
#unknown(arg = nil, &block) ⇒ Object
78 79 80 |
# File 'lib/redis/distributed_logger.rb', line 78 def unknown( arg = nil, &block ) add( UNKNOWN, block_given? ? yield : arg, block_given? ? arg : nil ) end |
#warn(arg = nil, &block) ⇒ Object
82 83 84 |
# File 'lib/redis/distributed_logger.rb', line 82 def warn( arg = nil, &block ) add( WARN, block_given? ? yield : arg, block_given? ? arg : nil ) end |
#warn? ⇒ Boolean
58 59 60 |
# File 'lib/redis/distributed_logger.rb', line 58 def warn? @_level <= WARN end |