class RemiLib::Logger

Overview

The base Logger class provides basic logging facilities.

The format of each message is:

[Header]: your message

Direct Known Subclasses

Defined in:

remilib/logging.cr

Constant Summary

ANSI_REGEX = Regex.new("\e\\[[0-9;]*m")

Constructors

Instance Method Summary

Constructor Detail

def self.new(*, ensureNewline : Bool = true, defaultHeader : String = "", verboseHeader : String = "Note", debugHeader : String = "Debug", warnHeader : String = "Warning", errorHeader : String = "Error", fatalHeader : String = "Fatal", showHeaders : Bool = true) #

[View source]

Instance Method Detail

def <<(text) #

Prints a message to #defaultStream by calling block, which must return a string. If #defaultHeader is not an empty string, then this will first print that header using #defaultColor.


[View source]
def debugColor : Symbol #

The color of the debug log header


[View source]
def debugColor=(debugColor : Symbol) #

The color of the debug log header


[View source]
def debugHeader : String #

The header printed before each debug log message.


[View source]
def debugHeader=(debugHeader : String) #

The header printed before each debug log message.


[View source]
def debugLevel : UInt8 #

The debugging level. See #dlog.


[View source]
def debugLevel=(debugLevel : UInt8) #

The debugging level. See #dlog.


[View source]
def debugStream : IO #

The stream that debug messages are printed to


[View source]
def debugStream=(debugStream : IO) #

The stream that debug messages are printed to


[View source]
def defaultColor : Symbol #

The color of the default log header


[View source]
def defaultColor=(defaultColor : Symbol) #

The color of the default log header


[View source]
def defaultHeader : String #

The default log header.


[View source]
def defaultHeader=(defaultHeader : String) #

The default log header.


[View source]
def defaultStream : IO #

The stream that #log/#vlog/#<< messages are printed to.


[View source]
def defaultStream=(defaultStream : IO) #

The stream that #log/#vlog/#<< messages are printed to.


[View source]
def dlog(minLevel : UInt8, msg : String) #

Prints a message to #debugStream if #debugLevel is greater than or equal to minLevel. This always prints a header using #debugHeader and #debugColor.

If #debugLevel is less than minLevel, this does nothing.

Returns true if a message was printed, or false otherwise.


[View source]
def dlog(minLevel : UInt8, &block : Proc(String)) : Bool #

Prints a message to #debugStream if #debugLevel is greater than or equal to minLevel by calling block, which must return a string. This always prints a header using #debugHeader and #debugColor.

If #debugLevel is less than minLevel, this does nothing.

Returns true if a message was printed, or false otherwise.


[View source]
def dlog(msg : String) : Bool #

Prints a message to #debugStream if #debugLevel is greater than or equal to 1. This always prints a header using #debugHeader and #debugColor.

Returns true if a message was printed, or false otherwise.


[View source]
def dlog(&block : Proc(String)) : Bool #

Prints a message to #debugStream if #debugLevel is greater than or equal to 1 by calling block, which must return a string. This always prints a header using #debugHeader and #debugColor.

Returns true if a message was printed, or false otherwise.


[View source]
def dlog!(msg : String) : Bool #

Prints a message to #debugStream regardless of #debugLevel. This always prints a header using #debugHeader and #debugColor.


[View source]
def dlog!(&block : Proc(String)) : Bool #

Prints a message to #debugStream regardless of #debugLevel. This always prints a header using #debugHeader and #debugColor.


[View source]
def ensureNewline=(ensureNewline : Bool) #

When true, all logging calls will ensure that a newline is printed after their message is printed.


[View source]
def ensureNewline? : Bool #

When true, all logging calls will ensure that a newline is printed after their message is printed.


[View source]
def error(msg : String) #

Prints a message to #errorStream. This always prints a header using #errorHeader and #errorColor.


[View source]
def error(&block : Proc(String)) #

Prints a message to #errorStream by calling block, which must return a string. This always prints a header using #errorHeader and #errorColor.


[View source]
def error(err : Exception) #

Prints an exception and its backtrace to #errorStream. This always prints a header using #errorHeader and #errorColor.


[View source]
def errorColor : Symbol #

The color of the error log header


[View source]
def errorColor=(errorColor : Symbol) #

The color of the error log header


[View source]
def errorHeader : String #

The header printed before each error log message.


[View source]
def errorHeader=(errorHeader : String) #

The header printed before each error log message.


[View source]
def errorStream : IO #

The stream that error messages are printed to


[View source]
def errorStream=(errorStream : IO) #

The stream that error messages are printed to


[View source]
def fatal(msg : String, exitCode = 1) : NoReturn #

Prints an error message to #errorStream, then calls exit with exitCode. This always uses the header "FATAL".


[View source]
def fatal(&block : Proc(Tuple(String, Int32))) : NoReturn #

Prints an error message to #errorStream by calling block. The block must return a tuple consisting of a string (the error message) and an Int32 (the exit code). This then calls exit with the exit code returned by `block. This always uses the header "FATAL".


[View source]
def fatal(err : Exception, exitCode = 1) : NoReturn #

Prints an exception and its backtrace to #errorStream, then calls exit with exitCode. This always uses the header "FATAL".


[View source]
def fatalHeader : String #

The header printed before a fatal log message.


[View source]
def fatalHeader=(fatalHeader : String) #

The header printed before a fatal log message.


[View source]
def forceFlush=(forceFlush : Bool) #

When true, IO#flush will be called after every log message. This applies to all streams associated with the instance.


[View source]
def forceFlush? : Bool #

When true, IO#flush will be called after every log message. This applies to all streams associated with the instance.


[View source]
def log(msg : String) #

Prints a message to #defaultStream. If #defaultHeader is not an empty string, then this will first print that header using #defaultColor.


[View source]
def log(&block : Proc(String)) #

Prints a message to #defaultStream by calling block, which must return a string. If #defaultHeader is not an empty string, then this will first print that header using #defaultColor.


[View source]
def noColors=(noColors : Bool) #

When true, color output is completely disabled.


[View source]
def noColors? : Bool #

When true, color output is completely disabled.


[View source]
def otherStreams : Array(IO) #

Additional streams to log messages to.


[View source]
def otherStreams=(otherStreams : Array(IO)) #

Additional streams to log messages to.


[View source]
def sanitizeOutput=(sanitizeOutput : Bool) #

When true, then all output will have meta characters (ESC, SUB, BEL, etc.) stripped from the output and replaced with textual representations.

See ::RemiLib.sanitize for more info.


[View source]
def sanitizeOutput? : Bool #

When true, then all output will have meta characters (ESC, SUB, BEL, etc.) stripped from the output and replaced with textual representations.

See ::RemiLib.sanitize for more info.


[View source]
def showHeaders=(showHeaders : Bool) #

When true, headers are shown for all of the logging messages. However, note that #log/#<< have additional constraints. See them for more details.


[View source]
def showHeaders? : Bool #

When true, headers are shown for all of the logging messages. However, note that #log/#<< have additional constraints. See them for more details.


[View source]
def timestamp : String #

When not String#empty?, use this as a Time::Format string to append a timestamp to each header. If this is empty, no timestamp is shown.

Note that if the header is also an empty string, no timestamp will be shown for that message.


[View source]
def timestamp=(timestamp : String) #

When not String#empty?, use this as a Time::Format string to append a timestamp to each header. If this is empty, no timestamp is shown.

Note that if the header is also an empty string, no timestamp will be shown for that message.


[View source]
def trace(msg : String) : Bool #

Prints a message to #debugStream only if #debugLevel is equal to 255. This always prints a header using #debugHeader and #debugColor.


[View source]
def trace(&block : Proc(String)) : Bool #

Prints a message to #debugStream by calling block (which must return a string), but only if #debugLevel is equal to 255. This always prints a header using #debugHeader and #debugColor.


[View source]
def verboseColor : Symbol #

The color of the verbose log header


[View source]
def verboseColor=(verboseColor : Symbol) #

The color of the verbose log header


[View source]
def verboseHeader : String #

The verbose log header.


[View source]
def verboseHeader=(verboseHeader : String) #

The verbose log header.


[View source]
def verbosityLevel : UInt8 #

The verbosity level. See #vlog.


[View source]
def verbosityLevel=(verbosityLevel : UInt8) #

The verbosity level. See #vlog.


[View source]
def vlog(minLevel : UInt8, msg : String) : Bool #

Prints a message to #defaultStream if #verbosityLevel is greater than or equal to minLevel. If #verboseHeader is not an empty string, then this will first print that header using #defaultColor.

If #verbosityLevel is less than minLevel, this does nothing.

Returns true if it printed something, or false otherwise.


[View source]
def vlog(minLevel : UInt8, &block : Proc(String)) : Bool #

Prints a message to #defaultStream if #verbosityLevel is greater than or equal to minLevel by calling block, which must return a string. If #verboseHeader is not an empty string, then this will first print that header using #defaultColor.

If #verbosityLevel is less than minLevel, this does nothing.

Returns true if it printed something, or false otherwise.


[View source]
def vlog(msg : String) : Bool #

Convenience function that just calls #vlog with a minimum level of 1.


[View source]
def vlog(&block : Proc(String)) : Bool #

Convenience function that just calls #vlog with a minimum level of 1.


[View source]
def warn(msg : String) #

Prints a message to #warnStream. This always prints a header using #warnHeader and #warnColor.


[View source]
def warn(&block : Proc(String)) #

Prints a message to #warnStream by calling block, which must return a string. This always prints a header using #warnHeader and #warnColor.


[View source]
def warn(err : Exception) #

Prints an exception and its backtrace to #warnStream. This always prints a header using #warnHeader and #warnColor.


[View source]
def warnColor : Symbol #

The color of the warning log header


[View source]
def warnColor=(warnColor : Symbol) #

The color of the warning log header


[View source]
def warnHeader : String #

The header printed before each warrning log message.


[View source]
def warnHeader=(warnHeader : String) #

The header printed before each warrning log message.


[View source]
def warnStream : IO #

The stream that warning messages are printed to


[View source]
def warnStream=(warnStream : IO) #

The stream that warning messages are printed to


[View source]