class Logger
Overview
The Logger class provides a simple but sophisticated logging utility that you can use to output messages.
The messages have associated levels, such as INFO or ERROR that indicate their importance. You can then give the Logger a level, and only messages at that level of higher will be printed.
For instance, in a production system, you may have your Logger set to INFO or even WARN. When you are developing the system, however, you probably want to know about the program’s internal state, and would set the Logger to DEBUG.
Example
require "logger"
log = Logger.new(STDOUT)
log.level = Logger::WARN
log.debug("Created logger")
log.info("Program started")
log.warn("Nothing to do!")
begin
File.each_line(path) do |line|
unless line =~ /^(\w+) = (.*)$/
log.error("Line in wrong format: #{line}")
end
end
rescue err
log.fatal("Caught exception; exiting")
log.fatal(err)
end
Defined in:
logger.crConstant Summary
-
DEBUG =
Severity::DEBUG
-
ERROR =
Severity::ERROR
-
FATAL =
Severity::FATAL
-
INFO =
Severity::INFO
-
UNKNOWN =
Severity::UNKNOWN
-
WARN =
Severity::WARN
Class Method Summary
Instance Method Summary
- #close
- #debug(message, progname = nil)
- #debug(progname = nil, &block)
- #debug?
- #error(message, progname = nil)
- #error(progname = nil, &block)
- #error?
- #fatal(progname = nil, &block)
- #fatal(message, progname = nil)
- #fatal?
- #formatter : String, Time, String, String, IO ->
- #formatter=(formatter)
- #info(progname = nil, &block)
- #info(message, progname = nil)
- #info?
- #level : Logger::Severity
- #level=(level : Severity)
- #log(severity, message, progname = nil)
- #log(severity, progname = nil, &block)
- #progname : String
- #progname=(progname : String)
- #unknown(message, progname = nil)
- #unknown(progname = nil, &block)
- #unknown?
- #warn(progname = nil, &block)
- #warn(message, progname = nil)
- #warn?
Instance methods inherited from class Reference
==(other)==(other : self) ==, hash hash, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, same?(other : Reference)
same?(other : Nil) same?, to_s(io : IO) : Nil to_s
Instance methods inherited from class Object
!=(other)
!=,
!~(other)
!~,
==(other)
==,
===(other)===(other : YAML::Any)
===(other : JSON::Any) ===, =~(other) =~, class class, clone clone, crystal_type_id crystal_type_id, dup dup, hash hash, inspect
inspect(io : IO) inspect, itself itself, not_nil! not_nil!, tap(&block) tap, to_json to_json, to_pretty_json(io : IO)
to_pretty_json to_pretty_json, to_s
to_s(io : IO) to_s, to_yaml(io : IO)
to_yaml to_yaml, try(&block) try