Class: ParticleLog
- Inherits:
-
Object
- Object
- ParticleLog
- Defined in:
- lib/particlelog.rb,
lib/particlelog/version.rb
Constant Summary collapse
- DEBUG =
0
- IO =
1
- INFO =
2
- WARNING =
3
- ERROR =
4
- IMPORTANT =
5
- CRITICAL =
7
- C_BOLD =
"\x1b[1m"
- C_RESET =
"\x1b[0m"
- C_CRESET =
"\x1b[39m"
- VERSION =
'0.1.1'
Instance Attribute Summary collapse
-
#color_table ⇒ Object
readonly
Returns the value of attribute color_table.
-
#level ⇒ Object
Returns the value of attribute level.
-
#level_table ⇒ Object
readonly
Returns the value of attribute level_table.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #critical(message, **opts) ⇒ Object
- #debug(message, **opts) ⇒ Object
- #error(message, **opts) ⇒ Object
- #important(message, **opts) ⇒ Object
- #info(message, **opts) ⇒ Object
-
#initialize(name, level) ⇒ ParticleLog
constructor
A new instance of ParticleLog.
- #inspect ⇒ Object
- #io(message, **opts) ⇒ Object
- #warning(message, **opts) ⇒ Object
- #write(message, **opts) ⇒ Object
Constructor Details
#initialize(name, level) ⇒ ParticleLog
Returns a new instance of ParticleLog.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/particlelog.rb', line 21 def initialize(name, level) @name = name @level = level @level_table = [ 'DBG', ' IO', 'INF', 'WRN', 'ERR', 'IMP', 'CRT' ] @color_table = [ "\x1b[32m", "\x1b[36m", "\x1b[34m", "\x1b[33m", "\x1b[31m", "\x1b[37m", "\x1b[35m" ] end |
Instance Attribute Details
#color_table ⇒ Object (readonly)
Returns the value of attribute color_table.
18 19 20 |
# File 'lib/particlelog.rb', line 18 def color_table @color_table end |
#level ⇒ Object
Returns the value of attribute level.
19 20 21 |
# File 'lib/particlelog.rb', line 19 def level @level end |
#level_table ⇒ Object (readonly)
Returns the value of attribute level_table.
18 19 20 |
# File 'lib/particlelog.rb', line 18 def level_table @level_table end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/particlelog.rb', line 18 def name @name end |
Instance Method Details
#critical(message, **opts) ⇒ Object
58 |
# File 'lib/particlelog.rb', line 58 def critical (, **opts) write(, **(opts.merge level: CRITICAL)) end |
#debug(message, **opts) ⇒ Object
52 |
# File 'lib/particlelog.rb', line 52 def debug (, **opts) write(, **(opts.merge level: DEBUG)) end |
#error(message, **opts) ⇒ Object
56 |
# File 'lib/particlelog.rb', line 56 def error (, **opts) write(, **(opts.merge level: ERROR)) end |
#important(message, **opts) ⇒ Object
57 |
# File 'lib/particlelog.rb', line 57 def important (, **opts) write(, **(opts.merge level: IMPORTANT)) end |
#info(message, **opts) ⇒ Object
54 |
# File 'lib/particlelog.rb', line 54 def info (, **opts) write(, **(opts.merge level: INFO)) end |
#inspect ⇒ Object
60 61 62 |
# File 'lib/particlelog.rb', line 60 def inspect "#<ParticleLog @name=#{@name.inspect} @level=#{@level_table[@level]}>" end |
#io(message, **opts) ⇒ Object
53 |
# File 'lib/particlelog.rb', line 53 def io (, **opts) write(, **(opts.merge level: IO)) end |
#warning(message, **opts) ⇒ Object
55 |
# File 'lib/particlelog.rb', line 55 def warning (, **opts) write(, **(opts.merge level: WARNING)) end |
#write(message, **opts) ⇒ Object
46 47 48 49 50 |
# File 'lib/particlelog.rb', line 46 def write(, **opts) level = opts[:level] || @level c = @color_table[level] STDERR.print "#{C_BOLD+c}[#{C_CRESET+DateTime.now.strftime+C_BOLD+c} | #{C_CRESET}#{@level_table[level]+C_BOLD+c}] #{C_RESET+name+C_BOLD+c}> #{C_RESET+}\n" end |