
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@nan0web/log
Advanced tools
A cross-platform Logger class that wraps console methods for both Node.js and browsers with consistent interface and streaming support.
A cross-platform Logger class that wraps console methods for both Node.js and browsers with consistent interface and streaming support.
The @nan0web/log package provides a minimal yet powerful foundation for logging systems.
Core classes:
Logger β main logger class with levels, icons, colors, time and streaming supportLogConsole β wraps console methods for consistent cross-platform loggingLoggerFormat β defines format for a logger level with icon, color and backgroundNoLogger β captures logs in memory, perfect for testingNoConsole β captures console output in memory, perfect for testingThese classes are perfect for building CLI tools, debugging layers, structured logs, and streaming data to files or external services.
How to install with npm?
npm install @nan0web/log
How to install with pnpm?
pnpm add @nan0web/log
How to install with yarn?
yarn add @nan0web/log
Logger can be instantiated with a level or options and logs everything below that level
How to create a Logger instance with level?
import Logger from '@nan0web/log'
const logger = new Logger('debug')
logger.info(typeof logger.debug) // β function
logger.info(logger.level) // β debug
How to create a Logger instance with options?
import Logger from '@nan0web/log'
const logger = new Logger({
level: 'info',
icons: true,
chromo: true,
time: true,
})
logger.info("Hello with options") // β TIME-HH-IIT... βΉ Hello with options
Logger supports custom formats for different levels
How to use custom formats for different levels?
import Logger from '@nan0web/log'
const logger = new Logger({
level: "debug",
icons: true,
formats: [
["debug", { icon: "π", color: Logger.CYAN }],
["info", { icon: "βΉοΈ ", color: Logger.GREEN }],
["warn", { icon: "β οΈ ", color: Logger.YELLOW }],
["error", { icon: "β", color: Logger.RED }],
["success", { icon: "β
", color: Logger.GREEN }],
]
})
logger.debug("Debug message") // β \x1b[36mπ Debug message
logger.info("Info message") // β \x1b[32mβΉοΈ Info message
logger.warn("Warning message") // β \x1b[33mβ οΈ Warning message
logger.error("Error message") // β \x1b[31mβ Error message
logger.success("Success message") // β \x1b[32mβ
Success message
Logger supports streaming logs to files or external services
How to stream logs to a file?
import Logger from '@nan0web/log'
let streamOutput = ""
const logger = new Logger({
stream: async (message) => {
streamOutput += message
}
})
logger.broadcast("Streamed message")
// Wait a bit for async operations
await new Promise(resolve => setTimeout(resolve, 10))
console.log(streamOutput) // β Streamed message
NoLogger captures logs in memory instead of printing them, perfect for testing
How to capture logs in memory with NoLogger?
import { NoLogger } from '@nan0web/log'
const logger = new NoLogger({ level: "debug" })
logger.debug("Debug message")
logger.info("Info message")
logger.warn("Warning message")
logger.error("Error message")
logger.success("Success message")
const logs = logger.output()
console.log(logs) // β [ [ "debug", "Debug message" ], [ "info", "Info message" ], ... ]
Logger includes useful helpers for formatting, tables, progress, etc.
How to create and display formatted tables?
import Logger from '@nan0web/log'
const logger = new Logger()
const data = [
{ name: "John", age: 30, city: "New York" },
{ name: "Jane", age: 25, city: "Los Angeles" },
{ name: "Bob", age: 35, city: "Chicago" }
]
// Capture table output by mocking console methods
logger.table(data, ["name", "age", "city"], { padding: 2, border: 1 })
// ------------------------
// name age city
// John 30 New York
// Jane 25 Los Angeles
// Bob 35 Chicago
// ------------------------
How to style text with colors and background?
import Logger from '@nan0web/log'
const styled = Logger.style("Styled text", {
color: Logger.MAGENTA,
bgColor: Logger.BG_WHITE
})
console.info(styled) // β \x1b[35m\x1b[47mStyled text\x1b[0m
Demonstrates moving the cursor, moving it down, and clearing a line.
The logger methods return the ANSI escape sequences, which you can log directly. Each call creates a separate log entry.
How to work with cursor and clear lines for progress?
const logger = new Logger()
// Log a multiline message
logger.info("Need to add first lines\nto let cursor move up")
// Log the cursorβup escape sequence β this is a separate log entry
logger.cursorUp(2, true)
// Log the clearβline escape sequence β a separate entry as well
logger.info(logger.clearLine())
Logger can prepend a custom prefix to every log line.
How to use Logger.prefix option?
const logger = new Logger({ prefix: "PREFIX> " })
logger.info("Message with prefix") // β PREFIX> Message with prefix
Properties
level β minimum log level to output (debug|info|warn|error|silent)console β Console instance used for outputicons β whether to show iconschromo β whether to apply colorstime β format for timestamps (default: false)spent β whether to log execution time differences (default: false)stream β function for output streaming (default: null)formats β map of formats for different log levelsMethods
debug(...args) β log debug messageinfo(...args) β log info messagewarn(...args) β log warning messageerror(...args) β log error messagesuccess(...args) β log success message (uses info channel)log(...args) β log generic messagesetFormat(target, opts) β set format for a log levelsetStream(streamFunction) β define stream function for outputtable(data, columns, options) β format and log table datawrite(str) β write string directly to stdoutcursorUp(lines) β move cursor up in terminalcursorDown(lines) β move cursor down in terminalclear() β clear the consoleclearLine() β clear the current linegetWindowSize() β get terminal size [columns, rows]cut(str, width) β cut string to terminal widthstatic from(input) β create Logger instance from string or optionsstatic detectLevel(argv) β detect log level from command line argsstatic createFormat(name, value) β create LoggerFormat from inputstatic style(value, styleOptions) β style a value with colorsstatic stripANSI(str) β remove ANSI codes from stringstatic progress(i, len, fixed) β calculate progress percentagestatic spent(checkpoint, fixed) β calculate time since checkpointstatic bar(i, len, width, char, space) β create progress bar stringProperties
console β the underlying console instanceprefix β prefix data for every logMethods
debug(...args) β log debug messageinfo(...args) β log info messagewarn(...args) β log warning messageerror(...args) β log error messagelog(...args) β log generic messageclear() β clear the consoleassert(condition, ...args) β assert a conditioncount(label) β log count of calls with labelcountReset(label) β reset counter for labeldir(obj) β display object propertiesdirxml(obj) β display object treegroup(...args) β create inline groupgroupCollapsed(...args) β create collapsed groupgroupEnd() β exit current groupprofile(label) β start profileprofileEnd(label) β end profiletime(label) β start timertimeStamp(label) β log timestamptimeEnd(label) β stop timer and log elapsed timetimeLog(label) β log current timer valuetable(data, columns) β display tabular datatrace() β log stack traceProperties
icon β icon stringcolor β ANSI color codebgColor β ANSI background color codeMethods
static from(input) β create format from object or existing instanceExtends Logger.
Properties
console β NoConsole instance that captures outputMethods
output() β return captured logsProperties
silent β whether to suppress all outputMethods
debug(...args) β capture debug loginfo(...args) β capture info logwarn(...args) β capture warning logerror(...args) β capture error loglog(...args) β capture generic logclear() β clear captured logsoutput(type) β return captured logs (all or filtered by type)static from(input) β create or return NoConsole instanceUses d.ts files for autocompletion
How to run playground script?
# Clone the repository and run the CLI playground
git clone https://github.com/nan0web/log.git
cd log
npm install
npm run play
How to contribute? - check here
How to license ISC? - check here
FAQs
A cross-platform Logger class that wraps console methods for both Node.js and browsers with consistent interface and streaming support.
We found that @nan0web/log demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.