LoggerStatic

About

This class provides static functions relevant to loggers globally. To access the functions in this class, use the Logger global method.

API

.add()

.add(name: Text; logger: cs.js.Logger) : cs.js.Logger

Adds a non-shared logger to the global logger registry under the given name. If an existing logger with the same name exists, its .close() function is called.

Once added to the registry, a shared copy of logger is returned and can later be retrieved via Logger.get().


.ansi()

.ansi(text : Text; color : Text) : Text

Wraps text in ANSI color codes for the given color. color may be several colors chained together with dots, e.g. "bold.green".

Whatever coloring is done to text is undone at the end of text, so you do not have to worry about restoring the colors to what they were before calling this function.

The possible ANSI color codes are:

Modifiers

bold
dim
inverse
italic
reset (removes all colors/modifiers)
strikethrough
underline

Text colors

black
blue
cyan
gray
green
magenta
red
white
yellow

Bright text colors

blackBright
blueBright
cyanBright
greenBright
magentaBright
redBright
whiteBright
yellowBright

Background colors

bgBlack
bgBlue
bgCyan
bgGray
bgGreen
bgMagenta
bgRed
bgWhite
bgYellow

Bright background colors

bgBlackBright
bgBlueBright
bgCyanBright
bgGreenBright
bgMagentaBright
bgRedBright
bgWhiteBright
bgYellowBright

Here is a sample of how these styles and colors look in a dark-themed terminal. The actual colors you will see depends on your terminal’s color scheme.

ansi


.create()

.create(name : Text { ; config: Object }) : cs.js.Logger

This is the function you should normally use to create a new logger. It does the following:

  • Instantiates a new Logger
  • Calls .add() to register the logger under name
  • Calls .configure() to configure the logger if config is not null
  • Returns the global shared copy of logger

.formats

.formats : cs.js.LogFormats

Returns the singleton LogFormats instance, which you use to customize the format of log messages. This property is read-only.


.get()

.get(name: Text) : cs.js.Logger

Retrieves the named logger from the global logger registry. If no such logger exists, null is returned.


.levels

.levels : Object

Returns the mapping from level names to numbers. This property is read-only.


.remove()

.remove(name: Text)

Removes the named logger from the global logger registry. If a logger with name exists in the registry, its .close() function is called.


.setColors()

.setColors(colors: Object)

This function allows you to customize the colors used for each of the five log levels. The standard colors are:

LevelColor
errorred
warnyellow
infogreen
verbosecyan
debugblue

For each key in colors that matches a level name, the corresponding value is set as the color. The value can be any valid value passed to the .ansi() function, for example "bold.red".


.stripAnsi()

.stripAnsi(text : Text) : Text

Removes any ANSI color codes from text and returns the result.

Last Updated:
Contributors: Aparajita