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:, env_debug_name: 'DEBUG') ⇒ 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:, env_debug_name: 'DEBUG') ⇒ Logger
Constructor for CLI::Kit::Logger
: (debug_log_file: String, ?env_debug_name: String) -> void
17 18 19 20 21 |
# File 'lib/cli/kit/logger.rb', line 17 def initialize(debug_log_file:, env_debug_name: 'DEBUG') FileUtils.mkpath(File.dirname(debug_log_file)) @debug_logger = ::Logger.new(debug_log_file, MAX_NUM_LOGS, MAX_LOG_SIZE) @env_debug_name = env_debug_name 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
: (String msg) -> void
72 73 74 75 |
# File 'lib/cli/kit/logger.rb', line 72 def debug(msg) $stdout.puts CLI::UI.fmt(msg) if 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
: (String msg, ?debug: bool) -> void
51 52 53 54 |
# File 'lib/cli/kit/logger.rb', line 51 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
: (String msg, ?debug: bool) -> void
62 63 64 65 |
# File 'lib/cli/kit/logger.rb', line 62 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
: (String msg, ?debug: bool) -> void
29 30 31 32 |
# File 'lib/cli/kit/logger.rb', line 29 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
: (String msg, ?debug: bool) -> void
40 41 42 43 |
# File 'lib/cli/kit/logger.rb', line 40 def warn(msg, debug: true) $stdout.puts CLI::UI.fmt("{{yellow:#{msg}}}") @debug_logger.warn(format_debug(msg)) if debug end |