Pinecone Logger
Small and fast logger, full of seeds!
const logger = ; logger; //Outputs: "[<date>] [INFO] TESTLOGGER - Hello world!"logger; //Outputs: "Some standard log."
Levels
Default levels are inspired by log4j levels.
LEVEL | Color | Description |
---|---|---|
Fatal | Red BG | Severe errors that cause premature termination. |
Error | Red | Other runtime errors or unexpected conditions. |
Warn | Yellow | Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". |
Success | Green | Successful events, completion of long tasks. |
Info | Cyan | Interesting runtime events (startup/shutdown). |
Debug | Magenta | Detailed information on the flow through the system. |
Trace | Blue | Most detailed information. |
Options
Several options are available to customize the logger.
const errLogger = ; errLogger; //Outputs nothing, "info" is higher than "error".errLogger; //Outputs: "[ERROR] errorLevelLogger - Some error!"
Option | Default | Description |
---|---|---|
level | "debug" | Maximum log level to process and print. |
name | "" | Can be set to improve log readability. |
nameColor | "grey" | Ansi color of the name. |
nameTransform | "uppercase" | Tranforms the name to uppercase or lowercase. |
dateFormat | "UTC" or "D MMM YYYY, HH:mm:ss.SSS Z" | Defines date format, requires "moment" for custom formats, only "UTC", "ISO" and "millis" are available otherwise. |
separator | "-" | Separator to use between log informations and log value. |
colorObjects | true | Enables standard utils.inpect() object coloration. |
disableColors | false | Disables all colors. |
inspectDepth | 3 | Defines utils.inpect() depth. |
showDate | true | Shows or hides date information. |
showLevel | true | Shows or hides level information. |
showName | true | Shows or hides name information. |
ellipsisAt | 64 | Ellipsis default max length. |
maxLength | 0 | Max log length, if a log is longer ellipsis will be used. |
output | null | Offers a single output solution for both stdout and stderr, is ignored if any of stdout and stderr are defined. |
stdout | process.stdout | Stdout, can be any writable stream, function, a string ("console", "stderr", "stdout") or an object with .write(chunk: string |
stderr | process.stderr | Stderr, can be any writable stream, function, a string ("console", "stderr", "stdout") or an object with .write(chunk: string |
noLog | false | Disables .log() method outputs. |
type | "string" | Can be both "string" or "json", if json log will be sent to any output as a JSON object. |
secretMask | "*" | Mask or Replacement Char for secrets, default *. |
secretLevel | "debug" | Required level for secrets to be visible. |
secretMaxLength | false | Limits the number of chars for masked secrets to improve readability. |
Secrets
Secrets help hiding sensible information while in production.
const infoLogger = ; const debugLogger = ;const user = "foo";const password = "bar123!";const secret = infoLogger;const iterableSecret = infoLogger; // When the secret is a single argument it is resolved while the log is processed by the logger.infoLogger; //Outputs: "User foo logged in with password *******".debugLogger; //Outputs: "User foo logged in with password bar123!". // String concatenation resolves the secret before the processing instead, so, if logger level < secret level, secret will be masked.infoLogger; //Outputs: "User foo logged in with password *******".debugLogger; //Outputs: "User foo logged in with password *******".console; //Outputs: "User foo logged in with password *******".debugLogger; //Outputs "User foo logged in with password bar123!" since both debugLogger and secret levels are "debug". // Iterable returns an array of secrets. Mask replaces the default '*'.infoLogger; //Outputs: "New user logged in.".debugLogger; //Outputs: "New user logged in.\n - User: foo \n - Password: bar123!".
Timers
Timers help visualizing how long is a given task. Timers are accessible from any logger from .timers property.
Logger .timers methods
Method | Args | Description |
---|---|---|
new() | name (string, optional) | Creates new timer. |
get() | name (string) or id (number) | Finds Timer by name or id. |
start() | name (string) or id (number) | Finds and starts a timer. |
stop() | name (string) or id (number) | Finds and stops a timer. |
resolve() | name (string) or id (number) | Finds and resolves a timer. |
valueOf() | name (string) or id (number) | Finds and returns the value of a timer. |
Timer object
Property | Description |
---|---|
id | Returns timer id. |
value | Returns timer value. |
Method | Description |
---|---|
start() | Starts the timer. |
stop() | Stops the timer. Can be resumed with "start()" |
resolve() | Resolves the timer. |
By resolving a timer its value will be returned and the timer itself will be deleted. Use "value" and "valueOf" to access value without stopping or destroying the timer.
const logger = ;const timer = loggertimersstart'timer1'; ; ;
Title
Title allows fast creation of standard titles.
Title accepts a string, for single-line titles, or an array of strings, for multi-line titles.
Three types are available:
----------------------------
-- This is a type 0 title --
-- Aligned left --
----------------------------
|----------------------------|
|-- This is a type 1 title --|
|-- Aligned right --|
|----------------------------|
/-----------------------------/
/-- This is a type 2 title ---/
/--- Aligned center --/
/-----------------------------/
logger.titletitle: string | string, options?: object
Option | Default | Description |
---|---|---|
char | "-" | Frame char. |
type | 0 | Type of title. Can be 0, 1 or 2. |
sideChar | "|", "/" | Side char(s). Available only for type 1 and 2. |
side | 2 | Represents how many "char" will be placed on text line sides. |
color | false | Text color. |
frameColor | false | Frame color. |
align | "left" | Multi-line text alignment. Can be "rignt", "left" or "center". |
const logger = ;logger;// -----------------------// -- Single line title --// ----------------------- logger;// ||============||// || Multi line ||// || ||// || Title ||// ||============||
Ellipsis
Ellipsis trims strings over a given length and places '...' (or else) at the end.
logger.ellipsisinput: string, length?: number, replacement?: string;
const logger = ;logger; // 123...logger; // 12345;
Groups
Groups can spread logs to multiple loggers with a single call.
logger.newGroup...members: Logger; group.addmembers: Logger;group.removemember: number|Logger;
const loggerParent = ;const loggerChild1 = ;const loggerChild2 = ;loggerParent; loggerParent;loggerChild1;loggerChild2;logger;const loggerGroup = loggerParent;loggerGroup;loggerGroup;loggerGroup;loggerGroup;loggerGroup;loggerGroup;loggerGroup;
Globals
Global loggers can be accessed anywhere.
// file 1const globalLogger = ;
// file 2const logger = globals;