A simple logger for Nit

Basic Usage

Create a new Logger with a severity level threshold set to warn_level:

var logger = new Logger(warn_level)

Messages with a severity equal or higher than warn_level will be displayed:

logger.error "Displays an error."
logger.warn "Displays a warning."

Messages with a lower severity are silenced:

logger.info "Displays nothing."

FileLogger can be used to output the messages into a file:

var log_file = "my.log"

logger = new FileLogger(warn_level, log_file, append = false)
logger.error("An error")
logger.info("Some info")
logger.close

assert log_file.to_path.read_all == "An error\n"
log_file.to_path.delete

Severity levels

Each message is associated with a level that indicate its severity. Only messages with a severity equal to or higher than the logger level threshold will be displayed.

Severity levels from the most severe to the least severe:

Formatting messages

You can create custom formatters by implementing the Formatter interface.

class MyFormatter
    super Formatter

    redef fun format(level, message) do
        if level < warn_level then return super
        return "!!!{message}!!!"
    end
end

See DefaultFormatter for a more advanced implementation example.

Each Logger can be given a default formatter used to format the every messages before outputting them:

var formatter = new MyFormatter
var stderr = new StringWriter
var logger = new Logger(warn_level, stderr, formatter)

logger.warn("This is a warning.")
assert stderr.to_s.trim.split("\n").last == "!!!This is a warning.!!!"

Optionally, a Formatter can be given to replace the default_formatter used by default:

logger = new Logger(warn_level, stderr, null)

# Display a message without any formatter
logger.warn("This is a warning.")
assert stderr.to_s.trim.split("\n").last == "This is a warning."

# Display a message with a custom formatter
logger.warn("This is a warning.", formatter)
assert stderr.to_s.trim.split("\n").last == "!!!This is a warning.!!!"

All subgroups and modules

module logger

logger :: logger

A simple logger for Nit
package_diagram logger\> logger console console logger\>->console core core console->core ...core ... ...core->core github github github->logger\> popcorn popcorn popcorn->logger\> popcorn->github popcorn... ... popcorn...->popcorn

Ancestors

group codecs

core > codecs

Group module for all codec-related manipulations
group collection

core > collection

This module define several collection classes.
group core

core

Nit common library of core classes and methods
group text

core > text

All the classes and methods related to the manipulation of text entities

Parents

group console

console

Defines some ANSI Terminal Control Escape Sequences.

Children

group github

github

Nit wrapper for Github API
group popcorn

popcorn

Popcorn

Descendants

group api

nitc > doc > api

Components required to build a web server about the nit model.
group catalog

nitc > catalog

Basic catalog generator for Nit packages
group commands

nitc > doc > commands

group compiler

nitc > compiler

Compilation to C
group compiler_ffi

nitc > compiler > compiler_ffi

Full FFI support for the compiler
group doc

nitc > doc

group dynamic_loading_ffi

nitc > interpreter > dynamic_loading_ffi

This group implement a partial support for the Nit FFI in the interpreter.
group ffi

nitc > ffi

Full FFI support, independent of the compiler
group frontend

nitc > frontend

Collect and orchestration of main frontend phases
group interpreter

nitc > interpreter

Interpretation of Nit programs
group metrics

nitc > metrics

Various statistics about Nit models and programs
group model

nitc > model

The meta model of Nit programs
group modelize

nitc > modelize

Create a model from nit source files
group nitc

nitc

Nit compiler and tools
group nitni

nitc > nitni

Native interface related services (used underneath the FFI)
group parser

nitc > parser

Parser and AST for the Nit language
group platform

nitc > platform

Platform system, used to customize the behavior of the compiler.
group saf

nitc > saf

Nit Static Analysis Framework.
group semantize

nitc > semantize

Process bodies of methods in regard with the model.
group static

nitc > doc > static

Nitdoc generation framework
group term

nitc > doc > term

group testing

nitc > testing

Test unit generation and execution for Nit.
group uml

nitc > uml

Group head module for UML generation services
group vm

nitc > vm

Entry point of all vm components