Class: Rubycord::Logger
- Inherits:
-
Object
- Object
- Rubycord::Logger
- Defined in:
- lib/rubycord/logger.rb
Overview
Logs debug messages
Constant Summary collapse
- MODES =
The modes this logger can have. This is probably useless unless you want to write your own Logger
-
{ debug: {long: "DEBUG", short: "D", format_code: ""}, good: {long: "GOOD", short: "✓", format_code: "\u001B[32m"}, # green info: {long: "INFO", short: "i", format_code: ""}, warn: {long: "WARN", short: "!", format_code: "\u001B[33m"}, # yellow error: {long: "ERROR", short: "✗", format_code: "\u001B[31m"}, # red out: {long: "OUT", short: "→", format_code: "\u001B[36m"}, # cyan in: {long: "IN", short: "←", format_code: "\u001B[35m"}, # purple ratelimit: {long: "RATELIMIT", short: "R", format_code: "\u001B[41m"} # red background }.freeze
- FORMAT_RESET =
The ANSI format code that resets formatting
-
"\u001B[0m"
- FORMAT_BOLD =
The ANSI format code that makes something bold
-
"\u001B[1m"
Instance Attribute Summary collapse
-
#fancy ⇒ true, false
writeonly
Whether this logger is in extra-fancy mode!.
-
#streams ⇒ Array<IO>, Array<#puts & #flush>
The streams the logger should write to.
-
#token ⇒ String?
writeonly
The bot token to be redacted or nil if it shouldn't.
Instance Method Summary collapse
-
#debug=(value) ⇒ Object
Sets the logging mode to :debug.
-
#initialize(fancy = false, streams = [$stdout]) ⇒ Logger
constructor
Creates a new logger.
-
#log_exception(e) ⇒ Object
Logs an exception to the console.
-
#mode=(value) ⇒ Object
Sets the logging mode Possible modes are: * :debug logs everything * :verbose logs everything except for debug messages * :normal logs useful information, warnings and errors * :quiet only logs warnings and errors * :silent logs nothing.
Constructor Details
#initialize(fancy = false, streams = [$stdout]) ⇒ Logger
Creates a new logger.
19 20 21 22 23 24 |
# File 'lib/rubycord/logger.rb', line 19 def initialize(fancy = false, streams = [$stdout]) @fancy = fancy self.mode = :normal @streams = streams end |
Instance Attribute Details
#fancy=(value) ⇒ true, false (writeonly)
Returns whether this logger is in extra-fancy mode!.
8 9 10 |
# File 'lib/rubycord/logger.rb', line 8 def fancy=(value) @fancy = value end |
#streams ⇒ Array<IO>, Array<#puts & #flush>
Returns the streams the logger should write to.
14 15 16 |
# File 'lib/rubycord/logger.rb', line 14 def streams @streams end |
#token=(value) ⇒ String? (writeonly)
Returns The bot token to be redacted or nil if it shouldn't.
11 12 13 |
# File 'lib/rubycord/logger.rb', line 11 def token=(value) @token = value end |
Instance Method Details
#debug=(value) ⇒ Object
Sets the logging mode to :debug
52 53 54 |
# File 'lib/rubycord/logger.rb', line 52 def debug=(value) self.mode = value ? :debug : :normal end |
#log_exception(e) ⇒ Object
Logs an exception to the console.
81 82 83 84 |
# File 'lib/rubycord/logger.rb', line 81 def log_exception(e) error("Exception: #{e.inspect}") e.backtrace.each { |line| error(line) } end |
#mode=(value) ⇒ Object
Sets the logging mode Possible modes are:
- :debug logs everything
- :verbose logs everything except for debug messages
- :normal logs useful information, warnings and errors
- :quiet only logs warnings and errors
- :silent logs nothing
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rubycord/logger.rb', line 64 def mode=(value) case value when :debug @enabled_modes = %i[debug good info warn error out in ratelimit] when :verbose @enabled_modes = %i[good info warn error out in ratelimit] when :normal @enabled_modes = %i[info warn error ratelimit] when :quiet @enabled_modes = %i[warn error] when :silent @enabled_modes = %i[] end end |