log 5.0.0
Install from the command line:
Learn more about npm packages
$ npm install @flex-development/log@5.0.0
Install via package.json:
"@flex-development/log": "5.0.0"
About this version
Log messages in the terminal and browser
This is a small, but useful, library for logging messages in the terminal and browser consoles.
Colorful messages can be logged in the terminal and browser consoles that support ANSI colors.
π Easy to use
π Pluggable reporters
π» Consistent terminal experience
π Tag support
π Browser support
This package is ESM only.
In Node.js with yarn:
yarn add @flex-development/logSee Git - Protocols | Yarn Β for details regarding installing from Git.
In Deno with esm.sh:
import { createLogger } from 'https://esm.sh/@flex-development/log'In browsers with esm.sh:
<script type="module">
import { logger } from 'https://esm.sh/@flex-development/log'
</script>With bun:
bun add @flex-development/log
See bun add for more details.
import { logger } from '@flex-development/log'
logger.info('Using @flex-development/log 5.0.0')
logger.start('Building project...')
logger.warn('A new version of @flex-development/log is available: 5.0.1')
logger.success('Project built!')
logger.fail(new Error('This is an example error. Everything is fine!'))Will display in the terminal:
This package exports the following identifiers:
The default export is logger.
(Logger) The default, pre-configured logger.
Logs are written using the FancyReporter.
Create a new logger.
-
options(LogLevelOption|LoggerOptions, optional) β Log level or configuration options
(Logger) Logger object
(Readonly<Record<LogType, LogLevel>>) Map where each key is a log type
and each value is a log level.
Log reporter (abstract class).
-
logger(Logger) β the loggerthisreporter writes to
Initialize the reporter.
-
logger(Logger) β the loggerthisreporter writes to
(this) this reporter
Define how a log message is processed and displayed by this reporter.
-
info(LogObject) β the log information to process
(undefined | void) Nothing.
Log reporter with basic utilities (abstract class).
Fancy log reporter (class).
This package is fully typed with TypeScript.
Logger API (TypeScript interface).
-
browser(boolean,readonly) β whether the logger is operating in a browser environment -
get color(): booleanβ whether color logs are enabled -
set color(color: boolean | null | undefined)β enable or disable color log. color will be disabled if not supported-
color(boolean | null | undefined) β color logs enabled?
-
-
get colors():Colorsβ get a colorizer based on the currentcolorconfiguration -
create(Create) β create a new logger, inheriting options from the current instance, with possible overrides -
defaults(InputLogObject) β properties to apply to all logs, regardless of log type or level -
eol(string) β the character, or characters, used to signify the end of a line -
format(LogFormatOptions) β formatting options -
get level():LogLevelβ get the current log level -
set level(level: LogLevelOption | null | undefined)β set the maximum log level to output-
level(LogLevelOption|null|undefined) β maximum log level (inclusive)
-
-
levels(Readonly<LogLevelMap>,readonly) β log level map -
reporters(Set<Reporter>,readonly) β list of reporter instances used to handle and output log messages -
stderr(WriteStream) β the writeable stream for standard error output -
stdout(WriteStream) β the writeable stream for standard output -
types(Record<LogType, InputLogObject>) β record, where each key is aLogTypeand each value is anInputLogObjectdefining the configuration for the log type -
unicode(boolean) β whether unicode is supported -
withDefaults(WithDefaults) β create a new logger with the specified default log object properties -
withTag(WithTag) β create a new logger with the specified tag. the tag will be included in any logs sent from the new logger
Create a new logger, inheriting options from the current instance, with possible overrides (TypeScript interface).
Plain objects (i.e. options.format, options.types) are merged recursively.
-
options(LoggerOptions, optional) β overrides for the new logger
(Logger) The new logger.
Input log data object (TypeScript interface).
-
additional?(string | string[], optional) β an additional line, or list of lines, to be logged with the message -
args?(unknown[], optional) β format arguments -
color?(Color, optional) β color associated with the log -
date?(Date, optional) β timestamp -
format?(LogFormatOptions, optional) β format options -
icon?(string, optional) β icon to display -
level?(LogLevelOption, optional) β log level -
message?(unknown, optional) β log message; inserted intoargsas the first format argument if defined -
stack?(string, optional) β stack trace -
tag?(string, optional) β a string to categorize or identify the log -
type?(LogType, optional) β log type
Use util.inspect on value and print its string representation (TypeScript type).
-
value(unknown) β the thing to inspect -
options(InspectOptions, optional) β inspection options
(undefined) Nothing.
Options for inspecting a value (TypeScript interface).
-
colors(boolean, optional) β whether to use color
Log formatting options (TypeScript interface).
-
badge?(boolean, optional) β whether to display the log type as a badge -
columns?(number, optional) β the maximum number of columns to output -
date?(boolean, optional) β whether to include timestamp information in log messages -
icon?(boolean, optional) β whether to display the icon associated with the log
Send a message to all reporter instances (TypeScript interface).
(message: InputLogObject | string, ...args: unknown[]) => undefined | void(message: unknown, ...args: unknown[]) => undefined | void
-
message(InputLogObject|unknown) β the message to write -
...args(unknown[], optional) β message arguments
(undefined | void) Nothing.
Log formatting options (TypeScript interface).
-
inspect(Inspect) β useutil.inspecton a value and print its string representation
Union of log levels (TypeScript type).
To register custom log levels, augment LogLevelMap.
They will be added to the union automatically.
type LogLevel = LogLevelMap[keyof LogLevelMap]Registry of log levels (TypeScript interface).
interface LogLevelMap {/* see code */}When developing extensions that use additional levels, augment LogLevelMap to register custom log levels:
declare module '@flex-development/log' {
interface LogLevelMap {
box: 3
}
}Union of log level options (TypeScript type).
type LogLevelOption = LogLevel | LogLevelTypeUnion of log level types (TypeScript type).
To register custom log level types, augment LogLevelMap.
They will be added to the union automatically.
type LogLevelType = Extract<keyof LogLevelMap, string>Log data object (TypeScript interface).
-
additional?(string[], optional) β additional lines to be logged with the message -
args(unknown[]) β format arguments -
date(Date) β timestamp -
level(LogLevel) β log level -
message?(null | undefined, optional) β log message -
type(LogType) β log type
Union of log types (TypeScript type).
To register custom log types, augment LogTypeMap.
They will be added to the union automatically.
type LogType = LogTypeMap[keyof LogTypeMap]Dictionary of log type functions (TypeScript type).
To register custom log type functions, augment LogTypeMap.
They will be added to the union automatically.
type LogTypeFunctions = { [T in LogType]: LogFunction }Registry of log types (TypeScript interface).
interface LogTypeMap {/* see code */}When developing extensions that use additional types, augment LogTypeMap to register custom log types:
declare module '@flex-development/log' {
interface LogTypeMap {
box: 'box'
}
}Logger configuration options (TypeScript interface).
-
defaults?(InputLogObject, optional) β properties to apply to all logs, regardless of log type or level. defaults can be overridden per log type usingtypes -
eol?(string, optional) β the character, or characters, used to signify the end of a line -
color?(Color) β color associated with the log -
format?(LogFormatOptions, optional) β formatting options -
level?(LogLevelOption, optional) β the maximum log level to output -
reporters?(ReportersOption, optional) β reporter instances used to handle and output log messages -
stderr?(WriteStream, optional) β the writeable stream for standard error output -
stdout?(WriteStream, optional) β the writeable stream for standard output -
types?(Partial<Record<LogType, InputLogObject>>, optional) β record, where each key is aLogTypeand each value is anInputLogObjectdefining the configuration for the log type
Union of values used to configure reporters (TypeScript type).
type ReportersOption =
| Reporter
| Set<Reporter | false | null | undefined>
| readonly (Reporter | false | null | undefined)[]Write data to the stream (TypeScript type).
-
buffer(string) β the data to write
(boolean | undefined | void) true if all data was flushed successfully, false if all or part of the data was
queued in user memory, or nothing.
Create a new logger with the specified default log object properties (TypeScript interface).
-
defaults(InputLogObject, optional) β default properties to apply to any log reported from the new logger
(Logger) The new logger.
Create a new logger with the specified tag (TypeScript interface).
-
tag(string) β the tag to include in each log reported from the new logger -
separator(string, optional) β the string to used separate tags- default:
':'
- default:
(Logger) The new logger.
Write stream API (TypeScript interface).
-
columns?(number, optional) β number of columns the tty currently has -
write(Write) β write data to the stream
See CONTRIBUTING.md.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
Details
- log
-
flex-development
- 4 months ago
- BSD-3-Clause
- 43 dependencies
Assets
- log-5.0.0.tgz
Download activity
- Total downloads 0
- Last 30 days 0
- Last week 0
- Today 0
