class Logger(T)

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.cr

Constant 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

Instance methods inherited from class Reference

! !, ==(other)
==(other : self)
==
, hash hash, inspect(io : IO) : Nil inspect, nil? nil?, object_id object_id, same?(other : Nil)
same?(other : Reference)
same?
, to_s(io : IO) : Nil to_s

Instance methods inherited from class Object

! !, !=(other) !=, !~(other) !~, ==(other) ==, ===(other) ===, =~(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

Class methods inherited from class Object

==(other : Class) ==, ===(other) ===, cast(other) : self cast, from_json(string_or_io) from_json, from_yaml(string : String) from_yaml, hash hash, inspect(io) inspect, name : String name, to_s(io) to_s

Class Method Detail

def self.new(io : T) #

[View source]

Instance Method Detail

def close #

[View source]
def debug(message, progname = nil) #

[View source]
def debug(progname = nil, &block) #

[View source]
def debug? #

[View source]
def error(progname = nil, &block) #

[View source]
def error(message, progname = nil) #

[View source]
def error? #

[View source]
def fatal(progname = nil, &block) #

[View source]
def fatal(message, progname = nil) #

[View source]
def fatal? #

[View source]
def formatter #

def formatter=(formatter) #

def info(progname = nil, &block) #

[View source]
def info(message, progname = nil) #

[View source]
def info? #

[View source]
def level #

def level=(level) #

def log(severity, message, progname = nil) #

[View source]
def log(severity, progname = nil, &block) #

[View source]
def progname #

def progname=(progname) #

def unknown(message, progname = nil) #

[View source]
def unknown(progname = nil, &block) #

[View source]
def unknown? #

[View source]
def warn(progname = nil, &block) #

[View source]
def warn(message, progname = nil) #

[View source]
def warn? #

[View source]