Class: Redis::DistributedLogger

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_formatObject

for compatibily with classic Logger methods



20
21
22
# File 'lib/redis/distributed_logger.rb', line 20

def datetime_format
  @datetime_format
end

#levelObject

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, message = nil, progname = nil, &block )
  @_redis.lpush( @_key, { at: Time.now.to_i, severity: severity, progname: block_given? ? message : progname, message: block_given? ? yield : message }.to_json )
end

#closeObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


58
59
60
# File 'lib/redis/distributed_logger.rb', line 58

def warn?
  @_level <= WARN
end