Class: CLI::Kit::Logger
- Inherits:
-
Object
- Object
- CLI::Kit::Logger
- Extended by:
- T::Sig
- 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
- #error(msg, debug: true) ⇒ Object
- #fatal(msg, debug: true) ⇒ Object
- #info(msg, debug: true) ⇒ Object
-
#initialize(debug_log_file:, env_debug_name: 'DEBUG') ⇒ Logger
constructor
A new instance of Logger.
- #warn(msg, debug: true) ⇒ Object
Methods included from T::Sig
Constructor Details
#initialize(debug_log_file:, env_debug_name: 'DEBUG') ⇒ Logger
Returns a new instance of Logger.
19 20 21 22 23 |
# File 'lib/cli/kit/logger.rb', line 19 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
74 75 76 77 |
# File 'lib/cli/kit/logger.rb', line 74 def debug(msg) $stdout.puts CLI::UI.fmt(msg) if debug? @debug_logger.debug(format_debug(msg)) end |
#error(msg, debug: true) ⇒ Object
53 54 55 56 |
# File 'lib/cli/kit/logger.rb', line 53 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
64 65 66 67 |
# File 'lib/cli/kit/logger.rb', line 64 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
31 32 33 34 |
# File 'lib/cli/kit/logger.rb', line 31 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
42 43 44 45 |
# File 'lib/cli/kit/logger.rb', line 42 def warn(msg, debug: true) $stdout.puts CLI::UI.fmt("{{yellow:#{msg}}}") @debug_logger.warn(format_debug(msg)) if debug end |