Class: CLI::Kit::Logger
- Inherits:
-
Object
- Object
- CLI::Kit::Logger
- Defined in:
- lib/cli/kit/logger.rb
Constant Summary collapse
- MAX_LOG_SIZE =
5MB
5 * 1024 * 1000
- MAX_NUM_LOGS =
10
Instance Method Summary collapse
-
#debug(msg) ⇒ Object
Similar to Logger#debug, however will not output to STDOUT unless DEBUG env var is set Logs to the debug file, taking into account CLI::UI::StdoutRouter.current_id.
-
#error(msg, debug: true) ⇒ Object
Functionally equivalent to Logger#error Also logs to the debug file, taking into account CLI::UI::StdoutRouter.current_id.
-
#fatal(msg, debug: true) ⇒ Object
Functionally equivalent to Logger#fatal Also logs to the debug file, taking into account CLI::UI::StdoutRouter.current_id.
-
#info(msg, debug: true) ⇒ Object
Functionally equivalent to Logger#info Also logs to the debug file, taking into account CLI::UI::StdoutRouter.current_id.
-
#initialize(debug_log_file:) ⇒ Logger
constructor
Constructor for CLI::Kit::Logger.
-
#warn(msg, debug: true) ⇒ Object
Functionally equivalent to Logger#warn Also logs to the debug file, taking into account CLI::UI::StdoutRouter.current_id.
Constructor Details
#initialize(debug_log_file:) ⇒ Logger
Constructor for CLI::Kit::Logger
13 14 15 16 |
# File 'lib/cli/kit/logger.rb', line 13 def initialize(debug_log_file:) FileUtils.mkpath(File.dirname(debug_log_file)) @debug_logger = ::Logger.new(debug_log_file, MAX_NUM_LOGS, MAX_LOG_SIZE) end |
Instance Method Details
#debug(msg) ⇒ Object
Similar to Logger#debug, however will not output to STDOUT unless DEBUG env var is set Logs to the debug file, taking into account CLI::UI::StdoutRouter.current_id
62 63 64 65 |
# File 'lib/cli/kit/logger.rb', line 62 def debug(msg) $stdout.puts CLI::UI.fmt(msg) if ENV['DEBUG'] @debug_logger.debug(format_debug(msg)) end |
#error(msg, debug: true) ⇒ Object
Functionally equivalent to Logger#error Also logs to the debug file, taking into account CLI::UI::StdoutRouter.current_id
43 44 45 46 |
# File 'lib/cli/kit/logger.rb', line 43 def error(msg, debug: true) $stderr.puts CLI::UI.fmt("{{red:#{msg}}}") @debug_logger.error(format_debug(msg)) if debug end |
#fatal(msg, debug: true) ⇒ Object
Functionally equivalent to Logger#fatal Also logs to the debug file, taking into account CLI::UI::StdoutRouter.current_id
53 54 55 56 |
# File 'lib/cli/kit/logger.rb', line 53 def fatal(msg, debug: true) $stderr.puts CLI::UI.fmt("{{red:{{bold:Fatal:}} #{msg}}}") @debug_logger.fatal(format_debug(msg)) if debug end |
#info(msg, debug: true) ⇒ Object
Functionally equivalent to Logger#info Also logs to the debug file, taking into account CLI::UI::StdoutRouter.current_id
23 24 25 26 |
# File 'lib/cli/kit/logger.rb', line 23 def info(msg, debug: true) $stdout.puts CLI::UI.fmt(msg) @debug_logger.info(format_debug(msg)) if debug end |
#warn(msg, debug: true) ⇒ Object
Functionally equivalent to Logger#warn Also logs to the debug file, taking into account CLI::UI::StdoutRouter.current_id
33 34 35 36 |
# File 'lib/cli/kit/logger.rb', line 33 def warn(msg, debug: true) $stdout.puts CLI::UI.fmt("{{yellow:#{msg}}}") @debug_logger.warn(format_debug(msg)) if debug end |