class Pandocomatic::Pandocomatic::Log
Pandocomatic’s log. Depending on given command-line arguments, pandocomatic will log its actions to file or not log anything at all.
Public Instance Methods
Log
a debug message
@param [String] msg
# File lib/pandocomatic/pandocomatic.rb, line 91 def debug(msg) @logger&.debug(msg) end
Log
an error message
@param [String] msg
# File lib/pandocomatic/pandocomatic.rb, line 98 def error(msg) @logger&.error(msg) end
Log
a fatal message
@param [String] msg
# File lib/pandocomatic/pandocomatic.rb, line 105 def fatal(msg) @logger&.fatal(msg) end
Indent given string with given number of spaces. Intended for logging purposes.
@param str [String] string to indent @param number_of_spaces [Number] number of spaces to indent string @return [String] indented string
# File lib/pandocomatic/pandocomatic.rb, line 129 def indent(str, number_of_spaces) str.split("\n").join("\n#{' ' * number_of_spaces}") end
Log
an informational message
@param [String] msg
# File lib/pandocomatic/pandocomatic.rb, line 112 def info(msg) @logger&.info(msg) end
Install a logger that writes to a given log file for given log level
@param log_file [String] name or path to log file @param log_level [String] log level, one of “fatal”, “error”, “warning”, or “debug”. Defaults to “info”
# File lib/pandocomatic/pandocomatic.rb, line 70 def install_file_logger(log_file, log_level = 'info') unless log_file.nil? begin @logger = Logger.new(log_file, level: log_level) @logger.formatter = proc do |severity, datetime, _progname, msg| date_format = datetime.strftime('%Y-%m-%d %H:%M:%S') "#{date_format} #{severity.ljust(5)}: #{msg}\n" end rescue StandardError => e warn "Unable to create log file '#{log_file}' with log level '#{log_level}' because:\n#{e}." warn 'Continuing with logging disabled.' end end info '------------ START ---------------' info "Running #{$PROGRAM_NAME} #{@args}" end
Add pandocomatic’s command-line arguments to the log
@param [String args
# File lib/pandocomatic/pandocomatic.rb, line 57 def pandocomatic_called_with(args) @args = if args.respond_to? :join args.join(' ') else args end end
Log
a warning message
@param [String] msg
# File lib/pandocomatic/pandocomatic.rb, line 119 def warn(msg) @logger&.warn(msg) end