### Install Signale using NPM Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Add the signale package to your project dependencies using NPM. ```bash npm install signale ``` -------------------------------- ### Install Signale using Yarn Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Add the signale package to your project dependencies using Yarn. ```bash yarn add signale ``` -------------------------------- ### Timer Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Start and manage timers for performance measurement. ```APIDOC ## signale.time([, label]) ### Description Starts a timer and accepts an optional label. If no label is provided, a unique label is automatically assigned. This method is useful for measuring the duration of operations. ### Parameters #### label - Type: `String` (Optional) - Description: The label for the timer. ### Return Type - `String`: The label of the timer. ### Request Example ```javascript const signale = require('signale'); const timerLabel = signale.time('my-timer'); // ... perform some operation ... signale.timeEnd(timerLabel); // Assuming timeEnd exists to stop the timer ``` ``` -------------------------------- ### Start a Timer with Signale Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Initialize a timer. If no label is provided, a default label like 'timer_0' will be used. You can specify a custom label for better organization. ```javascript const signale = require('signale'); signale.time(); //=> ▶ timer_0 Initialized timer... signale.time(); //=> ▶ timer_1 Initialized timer... signale.time('label'); //=> ▶ label Initialized timer... ``` -------------------------------- ### Start and End Timers with `signale.time()` and `signale.timeEnd()` Source: https://context7.com/klaudiosinani/signale/llms.txt Use `signale.time()` to start a named or auto-labeled timer, and `signale.timeEnd()` to stop it and log the elapsed time. `timeEnd()` without a label stops the most recently started auto-labeled timer. ```javascript const signale = require('signale'); // Named timer signale.time('db-query'); //=> ▶ db-query Initialized timer... // Auto-labeled timers const t1 = signale.time(); // => 'timer_0' const t2 = signale.time(); // => 'timer_1' //=> ▶ timer_0 Initialized timer... //=> ▶ timer_1 Initialized timer... setTimeout(() => { // Stops timer_1 (most recent auto-labeled) const r1 = signale.timeEnd(); //=> ◼ timer_1 Timer run for: 502ms console.log(r1); // { label: 'timer_1', span: 502 } // Stops timer_0 signale.timeEnd(); //=> ◼ timer_0 Timer run for: 503ms // Stops named timer const r2 = signale.timeEnd('db-query'); //=> ◼ db-query Timer run for: 503ms console.log(r2); // { label: 'db-query', span: 503 } }, 500); ``` -------------------------------- ### Create and Use Custom Signale Loggers Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Define custom loggers with specific badges, colors, and labels by passing a configuration object with a 'types' field to the Signale constructor. This example adds 'remind' and 'santa' loggers. ```javascript const {Signale} = require('signale'); const options = { disabled: false, interactive: false, logLevel: 'info', scope: 'custom', secrets: [], stream: process.stdout, types: { remind: { badge: '**', color: 'yellow', label: 'reminder', logLevel: 'info' }, santa: { badge: '🎅', color: 'red', label: 'santa', logLevel: 'info' } } }; const custom = new Signale(options); custom.remind('Improve documentation.'); custom.santa('Hoho! You have an unused variable on L45.'); ``` -------------------------------- ### Configure Writable Streams for Signale Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Customize where Signale logs messages by setting the `stream` option. This example directs all logs to `stderr` and specifically configures the `error` type to log to both `stdout` and `stderr`. ```javascript const {Signale} = require('signale'); const options = { stream: process.stderr, // All loggers will now write to `process.stderr` types: { error: { // Only `error` will write to both `process.stdout` & `process.stderr` stream: [process.stdout, process.stderr] } } }; const signale = new Signale(options); signale.success('Message will appear on `process.stderr`'); signale.error('Message will appear on both `process.stdout` & `process.stderr`'); ``` -------------------------------- ### signale.time() and signale.timeEnd() Source: https://context7.com/klaudiosinani/signale/llms.txt Starts and stops named or auto-labeled timers to measure elapsed time. `time()` returns the label, and `timeEnd()` returns an object containing the label and the elapsed time in milliseconds. ```APIDOC ## `signale.time([label])` and `signale.timeEnd([label])` — Timers `time()` starts a named timer and returns the label string. `timeEnd()` stops the timer and returns `{ label, span }` where `span` is elapsed milliseconds. Calling `timeEnd()` without a label stops the most recently auto-labeled timer. ### Usage ```js const signale = require('signale'); // Named timer signale.time('db-query'); //=> ▶ db-query Initialized timer... // Auto-labeled timers const t1 = signale.time(); // => 'timer_0' const t2 = signale.time(); // => 'timer_1' //=> ▶ timer_0 Initialized timer... //=> ▶ timer_1 Initialized timer... setTimeout(() => { // Stops timer_1 (most recent auto-labeled) const r1 = signale.timeEnd(); //=> ◼ timer_1 Timer run for: 502ms console.log(r1); // { label: 'timer_1', span: 502 } // Stops timer_0 signale.timeEnd(); //=> ◼ timer_0 Timer run for: 503ms // Stops named timer const r2 = signale.timeEnd('db-query'); //=> ◼ db-query Timer run for: 503ms console.log(r2); // { label: 'db-query', span: 503 } }, 500); ``` ``` -------------------------------- ### Filter Secrets in Signale Logs Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Prevent sensitive information like usernames or tokens from appearing in logs by using the `secrets` option. This example demonstrates filtering and how scoped loggers inherit these secrets. ```javascript const {Signale} = require('signale'); // In reality secrets could be securely fetched/decrypted through a dedicated API const [USERNAME, TOKEN] = ['klaudiosinani', 'token']; const logger1 = new Signale({ secrets: [USERNAME, TOKEN] }); logger1.log('$ exporting USERNAME=%s', USERNAME); logger1.log('$ exporting TOKEN=%s', TOKEN); // `logger2` inherits all secrets from its parent `logger1` const logger2 = logger1.scope('parent'); logger2.log('$ exporting USERNAME=%s', USERNAME); logger2.log('$ exporting TOKEN=%s', TOKEN); ``` -------------------------------- ### Use Default Signale Logger Methods Source: https://context7.com/klaudiosinani/signale/llms.txt Demonstrates various ways to use the default Signale instance for logging. Supports plain strings, multiple strings, printf-style formatting, Error objects, and structured objects for messages. ```javascript const signale = require('signale'); // Plain string signale.success('Build completed successfully'); //=> ✔ success Build completed successfully // Multiple strings (space-joined) signale.info('Server', 'running on', 'port 3000'); //=> ℹ info Server running on port 3000 // Printf-style interpolation signale.pending('Deploying version %s to %s', '2.1.0', 'production'); //=> … pending Deploying version 2.1.0 to production // Error object (prints stack trace) signale.error(new Error('Connection refused')); //=> ✖ error Error: Connection refused // at Object. (/app/server.js:10:15) // ... // fatal (same level as error) signale.fatal(new Error('Out of memory')); // Structured object with prefix and suffix signale.complete({ prefix: '[CI]', message: 'All tests passed', suffix: '(3/3)' }); //=> [CI] ☒ complete All tests passed (3/3) // All available default loggers: signale.await('Fetching remote config...'); // ℹ awaiting signale.debug('Cache hit for key:', 'user:42'); // ⬤ debug signale.fav('New favorite added'); // ❤ favorite signale.note('Remember to update the docs'); // • note signale.pause('Worker paused'); // ▪ pause signale.star('New release is out!'); // ★ star signale.start('Starting build pipeline'); // ▶ start signale.wait('Waiting for lock to release'); // … waiting signale.warn('Deprecated API used at L42'); // ⚠ warning signale.watch('Watching src/ for changes'); // … watching signale.log('Raw message without label'); // (no badge/label) ``` -------------------------------- ### Configure Signale Instance with `signale.config()` Source: https://context7.com/klaudiosinani/signale/llms.txt Use `signale.config()` to override display settings for a specific Signale instance at runtime. Local configuration takes precedence over global settings. Scoped loggers can also override their parent's configuration. ```javascript const signale = require('signale'); // Enable filename, timestamp, and date metadata signale.config({ displayFilename: true, displayTimestamp: true, displayDate: true, displayScope: true, displayBadge: true, displayLabel: true, underlineLabel: true, uppercaseLabel: false }); signale.success('Config applied'); //=> [2024-03-15] [14:23:07] [app.js] › ✔ success Config applied // Scoped logger with its own config override const db = signale.scope('db'); db.config({ displayDate: false, displayTimestamp: false }); db.info('Query executed in 4ms'); //=> [db] › ℹ info Query executed in 4ms ``` -------------------------------- ### Global Signale Configuration in `package.json` Source: https://context7.com/klaudiosinani/signale/llms.txt Define project-wide default Signale settings by adding a `signale` object to your `package.json`. These settings are automatically picked up and can be overridden by per-instance `config()` calls. ```json { "name": "my-project", "signale": { "displayScope": true, "displayBadge": true, "displayDate": false, "displayFilename": true, "displayLabel": true, "displayTimestamp": true, "underlineLabel": true, "underlineMessage": false, "underlinePrefix": false, "underlineSuffix": false, "uppercaseLabel": false } } ``` -------------------------------- ### Global Configuration via package.json Source: https://context7.com/klaudiosinani/signale/llms.txt Sets project-wide default logging configurations for all Signale instances. These settings are automatically detected from the `signale` key in `package.json` and can be overridden by per-instance `config()` calls. ```APIDOC ## Global Configuration via `package.json` Sets project-wide defaults for all Signale instances. Any key under `"signale"` in `package.json` is picked up automatically via `pkg-conf`. Per-instance `config()` calls always override these. ### Example `package.json` Configuration ```json { "name": "my-project", "signale": { "displayScope": true, "displayBadge": true, "displayDate": false, "displayFilename": true, "displayLabel": true, "displayTimestamp": true, "underlineLabel": true, "underlineMessage": false, "underlinePrefix": false, "underlineSuffix": false, "uppercaseLabel": false } } ``` ``` -------------------------------- ### signale.config(settingsObj) Source: https://context7.com/klaudiosinani/signale/llms.txt Overrides display settings on any Signale instance at runtime. Local configuration takes precedence over global settings. Scoped loggers can independently override inherited configurations. ```APIDOC ## `signale.config(settingsObj)` — Instance Configuration Overrides display settings on any Signale instance at runtime. Local config always wins over `package.json` global config. Scoped loggers inherit their parent's config but can independently override it. ### Usage ```js const signale = require('signale'); // Enable filename, timestamp, and date metadata signale.config({ displayFilename: true, displayTimestamp: true, displayDate: true, displayScope: true, displayBadge: true, displayLabel: true, underlineLabel: true, uppercaseLabel: false }); signale.success('Config applied'); //=> [2024-03-15] [14:23:07] [app.js] › ✔ success Config applied // Scoped logger with its own config override const db = signale.scope('db'); db.config({ displayDate: false, displayTimestamp: false }); db.info('Query executed in 4ms'); //=> [db] › ℹ info Query executed in 4ms ``` ``` -------------------------------- ### Configuration Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Configure logger settings globally or locally to customize output. ```APIDOC ## signale.config(settingsObj) ### Description Sets the configuration for a Signale instance, overriding any existing global or local configurations. ### Parameters #### settingsObj - Type: `Object` - Description: An object containing configuration options. Available options include `underlineLabel`, `underlineMessage`, `underlinePrefix`, `underlineSuffix`, `uppercaseLabel`, `displayFilename`, `displayTimestamp`, and `displayDate`. ### Request Example ```javascript // foo.js const signale = require('signale'); signale.config({ displayFilename: true, displayTimestamp: true, displayDate: true }); signale.success('Successful operations'); ``` ### Response Example ``` // For signale.success('Successful operations') with the above config: // [2018-5-15] [11:12:38] [foo.js] › ✔ success Successful operations ``` ``` -------------------------------- ### signale.time() Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Initializes a new timer. If a label is provided, it corresponds to that timer; otherwise, a default label is used. ```APIDOC ## signale.time([label]) ### Description Initializes a new timer. If a label is provided, it corresponds to that timer; otherwise, a default label is used. ### Parameters #### Path Parameters - **label** (String) - Optional - Label corresponding to the timer. Each timer must have its own unique label. ### Request Example ```js const signale = require('signale'); signale.time(); //=> ▶ timer_0 Initialized timer... signale.time('myCustomLabel'); //=> ▶ myCustomLabel Initialized timer... ``` ``` -------------------------------- ### signale.scope(...name) Source: https://context7.com/klaudiosinani/signale/llms.txt Creates a new Signale instance with a prepended scope name. This allows for hierarchical logging contexts, and the new instance inherits all configurations from the parent. ```APIDOC ## `signale.scope(...name)` — Scoped Loggers Creates a new Signale instance that inherits all configuration, custom types, secrets, streams, log level, and interactive mode from the parent. The scope name is prepended to every log line. Multiple scope names produce chained brackets. ### Usage ```js const signale = require('signale'); // Create from the default instance const appLogger = signale.scope('app'); appLogger.info('Application booting'); //=> [app] › ℹ info Application booting // Chain scopes for nested context const dbLogger = appLogger.scope('app', 'database'); dbLogger.success('Connection pool initialized (size: 10)'); //=> [app] [database] › ✔ success Connection pool initialized (size: 10) // Create from a custom instance — inherits all custom types const { Signale } = require('signale'); const base = new Signale({ types: { ship: { badge: '🚢', color: 'blue', label: 'ship', logLevel: 'info' } } }); const scoped = base.scope('release'); scoped.ship('v3.0.0 shipped'); //=> [release] › 🚢 ship v3.0.0 shipped ``` ``` -------------------------------- ### Configure Global Logger Settings Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Set global configuration options for the Signale instance. These settings override any configurations from package.json. ```javascript // foo.js const signale = require('signale'); signale.config({ displayFilename: true, displayTimestamp: true, displayDate: true }); signale.success('Successful operations'); //=> [2018-5-15] [11:12:38] [foo.js] › ✔ success Successful operations ``` -------------------------------- ### Create Scoped Logger with Options Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Use this to create a new Signale instance with a predefined scope. The 'scope' option is passed within the options object. ```javascript const {Signale} = require('signale'); const options = { scope: 'global scope' }; const global = new Signale(options); global.success('Successful Operation'); ``` -------------------------------- ### Create Custom Signale Logger Instance Source: https://context7.com/klaudiosinani/signale/llms.txt Instantiates a new Signale logger with custom configurations and logger types. Allows overriding built-in types or defining entirely new ones with custom badges, colors, and labels. ```javascript const { Signale } = require('signale'); const logger = new Signale({ disabled: false, interactive: false, logLevel: 'info', // 'info' | 'timer' | 'debug' | 'warn' | 'error' scope: 'my-app', secrets: [], stream: process.stdout, types: { // Brand-new custom logger type deploy: { badge: '🚀', color: 'cyan', label: 'deploy', logLevel: 'info' }, // Override the built-in error logger error: { badge: '💥', label: 'FATAL ERROR', color: 'red' } } }); logger.deploy('Pushing image to registry: myapp:latest'); //=> [my-app] › 🚀 deploy Pushing image to registry: myapp:latest logger.error('Database unreachable'); //=> [my-app] › 💥 FATAL ERROR Database unreachable logger.success('Service started'); //=> [my-app] › ✔ success Service started ``` -------------------------------- ### Create and Use Scoped Loggers Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Create loggers with specific scopes to namespace log output. Multiple scope names can be combined. ```javascript const signale = require('signale'); const foo = signale.scope('foo'); const fooBar = signale.scope('foo', 'bar'); foo.success('foo'); //=> [foo] › ✔ success foo fooBar.success('foo bar'); //=> [foo] [bar] › ✔ success foo bar ``` -------------------------------- ### Create Scoped Loggers with `signale.scope()` Source: https://context7.com/klaudiosinani/signale/llms.txt Use `signale.scope()` to create new logger instances that inherit configuration and prepend scope names to log messages. Multiple scopes can be chained for nested context. ```javascript const signale = require('signale'); // Create from the default instance const appLogger = signale.scope('app'); appLogger.info('Application booting'); //=> [app] › ℹ info Application booting // Chain scopes for nested context const dbLogger = appLogger.scope('app', 'database'); dbLogger.success('Connection pool initialized (size: 10)'); //=> [app] [database] › ✔ success Connection pool initialized (size: 10) // Create from a custom instance — inherits all custom types const { Signale } = require('signale'); const base = new Signale({ types: { ship: { badge: '🚢', color: 'blue', label: 'ship', logLevel: 'info' } } }); const scoped = base.scope('release'); scoped.ship('v3.0.0 shipped'); //=> [release] › 🚢 ship v3.0.0 shipped ``` -------------------------------- ### signale.enable() Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Enables the logging functionality for all loggers within a specific Signale instance. ```APIDOC ## signale.enable() ### Description Enables the logging functionality of all loggers belonging to a specific instance. ### Request Example ```js const signale = require('signale'); signale.disable(); signale.success('This will NOT be logged'); //=> signale.enable(); signale.success('This will be logged again'); //=> ✔ success This will be logged again ``` ``` -------------------------------- ### Basic Usage of Default Signale Loggers Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Import and use various default loggers provided by Signale for different logging needs. Supports string interpolation for messages. ```javascript const signale = require('signale'); signale.success('Operation successful'); signale.debug('Hello', 'from', 'L59'); signale.pending('Write release notes for %s', '1.2.0'); signale.fatal(new Error('Unable to acquire lock')); signale.watch('Recursively watching build directory...'); signale.complete({prefix: '[task]', message: 'Fix issue #59', suffix: '(@klaudiosinani)'}); ``` -------------------------------- ### Create Scoped Logger from Existing Instance Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Use the scope() function on an existing Signale instance to create a new instance that inherits all configurations. Multiple scope names can be provided. ```javascript const signale = require('signale'); const global = signale.scope('global scope'); global.success('Hello from the global scope'); function foo() { const outer = global.scope('outer', 'scope'); outer.success('Hello from the outer scope'); setTimeout(() => { const inner = outer.scope('inner', 'scope'); inner.success('Hello from the inner scope'); }, 500); } foo(); ``` -------------------------------- ### Enable Logging with Signale Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Enables logging functionality for the current Signale instance. This is useful after logging has been disabled. ```javascript const signale = require('signale'); signale.disable(); signale.success('foo'); //=> signale.enable(); signale.success('foo'); //=> ✔ success foo ``` -------------------------------- ### Configure Local Logger Instance Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Override global or package.json configurations for a specific logger instance. Useful for file-specific logging settings. ```javascript const signale = require('signale'); // Overrides any existing `package.json` config signale.config({ displayFilename: true, displayTimestamp: true, displayDate: false }); signale.success('Hello from the Global scope'); ``` -------------------------------- ### Custom Logger Instance Source: https://context7.com/klaudiosinani/signale/llms.txt Create a new Signale instance with custom logger types and behavior using the `Signale` class constructor. Options include `disabled`, `interactive`, `logLevel`, `scope`, `secrets`, `stream`, and `types` for defining new or overriding existing loggers. ```APIDOC ## `new Signale(options)` — Custom Logger Instance Creates a new Signale instance with custom logger types and behavior. The `types` field lets you define brand-new loggers or override existing ones by reusing their names. All options (`disabled`, `interactive`, `logLevel`, `scope`, `secrets`, `stream`, `types`) are optional. ```js const { Signale } = require('signale'); const logger = new Signale({ disabled: false, interactive: false, logLevel: 'info', // 'info' | 'timer' | 'debug' | 'warn' | 'error' scope: 'my-app', secrets: [], stream: process.stdout, types: { // Brand-new custom logger type deploy: { badge: '🚀', color: 'cyan', label: 'deploy', logLevel: 'info' }, // Override the built-in error logger error: { badge: '💥', label: 'FATAL ERROR', color: 'red' } } }); logger.deploy('Pushing image to registry: myapp:latest'); //=> [my-app] › 🚀 deploy Pushing image to registry: myapp:latest logger.error('Database unreachable'); //=> [my-app] › 💥 FATAL ERROR Database unreachable logger.success('Service started'); //=> [my-app] › ✔ success Service started ``` ``` -------------------------------- ### Default Logger Methods Source: https://context7.com/klaudiosinani/signale/llms.txt Signale provides 16 built-in log methods that can be called directly on the default instance. These methods support various input types including plain strings, multiple strings, printf-style format strings, Error objects, and structured objects. ```APIDOC ## Default Logger Methods Every Signale instance exposes all 16 built-in log methods directly. Each method accepts a plain string, multiple strings (joined), printf-style format strings, an `Error` object, or a structured `{ prefix, message, suffix }` object. ```js const signale = require('signale'); // Plain string signale.success('Build completed successfully'); //=> ✔ success Build completed successfully // Multiple strings (space-joined) signale.info('Server', 'running on', 'port 3000'); //=> ℹ info Server running on port 3000 // Printf-style interpolation signale.pending('Deploying version %s to %s', '2.1.0', 'production'); //=> … pending Deploying version 2.1.0 to production // Error object (prints stack trace) signale.error(new Error('Connection refused')); //=> ✖ error Error: Connection refused // at Object. (/app/server.js:10:15) // ... // fatal (same level as error) signale.fatal(new Error('Out of memory')); // Structured object with prefix and suffix signale.complete({ prefix: '[CI]', message: 'All tests passed', suffix: '(3/3)' }); //=> [CI] ☒ complete All tests passed (3/3) // All available default loggers: signale.await('Fetching remote config...'); // ℹ awaiting signale.debug('Cache hit for key:', 'user:42'); // ⬤ debug signale.fav('New favorite added'); // ❤ favorite signale.note('Remember to update the docs'); // • note signale.pause('Worker paused'); // ▪ pause signale.star('New release is out!'); // ★ star signale.start('Starting build pipeline'); // ▶ start signale.wait('Waiting for lock to release'); // … waiting signale.warn('Deprecated API used at L42'); // ⚠ warning signale.watch('Watching src/ for changes'); // … watching signale.log('Raw message without label'); // (no badge/label) ``` ``` -------------------------------- ### Initialize Interactive Logger Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Initialize an interactive logger by setting the 'interactive' attribute to true in the Signale constructor options. Interactive loggers override previous messages from other interactive loggers. ```javascript const {Signale} = require('signale'); const interactive = new Signale({interactive: true, scope: 'interactive'}); interactive.await('[%d/4] - Process A', 1); setTimeout(() => { interactive.success('[%d/4] - Process A', 2); setTimeout(() => { interactive.await('[%d/4] - Process B', 3); setTimeout(() => { interactive.error('[%d/4] - Process B', 4); setTimeout(() => {}, 1000); }, 1000); }, 1000); }, 1000); ``` -------------------------------- ### Toggle Logging with `signale.disable()`, `signale.enable()`, `signale.isEnabled()` Source: https://context7.com/klaudiosinani/signale/llms.txt Control logging output for a Signale instance using `disable()` to silence logs and `enable()` to resume them. `isEnabled()` returns a boolean indicating the current logging state. This is useful for suppressing logs in specific environments. ```javascript const { Signale } = require('signale'); const logger = new Signale({ scope: 'worker' }); logger.success('Started'); //=> [worker] › ✔ success Started logger.disable(); console.log(logger.isEnabled()); // false logger.success('This is suppressed'); //=> (no output) logger.enable(); console.log(logger.isEnabled()); // true logger.success('Resumed'); //=> [worker] › ✔ success Resumed ``` -------------------------------- ### Log Levels Configuration in Signale Source: https://context7.com/klaudiosinani/signale/llms.txt Control log output verbosity using the `logLevel` option. This sets a minimum threshold for messages to be displayed. Logger types also have their own `logLevel` which is compared against the instance threshold. ```javascript const { Signale } = require('signale'); // Only warn and error messages will be shown in production const prodLogger = new Signale({ logLevel: 'warn' }); prodLogger.info('Cache primed'); // suppressed (info < warn) prodLogger.debug('Query plan: ...'); // suppressed (debug < warn) prodLogger.warn('High memory usage'); //=> ⚠ warning High memory usage prodLogger.error('Disk full'); //=> ✖ error Disk full // Level hierarchy (low → high): // info (0) → timer (1) → debug (2) → warn (3) → error (4) const devLogger = new Signale({ logLevel: 'debug' }); devLogger.debug('Entering handler'); //=> shown devLogger.info('Request received'); // suppressed (info < debug) ``` -------------------------------- ### Log Simple Messages Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Log messages using default loggers or by providing multiple string arguments. Supports string interpolation for dynamic messages. ```javascript const signale = require('signale'); signale.success('Successful operation'); //=> ✔ success Successful operation signale.success('Successful', 'operation'); //=> ✔ success Successful operation signale.success('Successful %s', 'operation'); //=> ✔ success Successful operation ``` -------------------------------- ### signale.disable(), signale.enable(), signale.isEnabled() Source: https://context7.com/klaudiosinani/signale/llms.txt Provides methods to temporarily silence or re-enable all logging output from a Signale instance without altering its configuration. This is useful for controlling logs in specific environments like testing. ```APIDOC ## `signale.disable()`, `signale.enable()`, `signale.isEnabled()` — Toggle Logging Silences or re-enables all output from a specific instance without changing its configuration. Useful for suppressing logs in test environments or on-demand. ### Usage ```js const { Signale } = require('signale'); const logger = new Signale({ scope: 'worker' }); logger.success('Started'); //=> [worker] › ✔ success Started logger.disable(); console.log(logger.isEnabled()); // false logger.success('This is suppressed'); //=> (no output) logger.enable(); console.log(logger.isEnabled()); // true logger.success('Resumed'); //=> [worker] › ✔ success Resumed ``` ``` -------------------------------- ### Log Error Objects Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Log instances of the Error object. Signale will format the error output including the stack trace. ```javascript const signale = require('signale'); signale.error(new Error('Unsuccessful operation')); //=> ✖ error Error: Unsuccessful operation // at Module._compile (module.js:660:30) // at Object.Module._extensions..js (module.js:671:10) // ... ``` -------------------------------- ### Log Message Objects with Prefix and Suffix Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Log complex messages using an object that includes prefix, message, and suffix. Supports string interpolation within the message array. ```javascript const signale = require('signale'); signale.complete({prefix: '[task]', message: 'Fix issue #59', suffix: '(@klaudiosinani)'}); //=> [task] ☒ complete Fix issue #59 (@klaudiosinani) signale.complete({prefix: '[task]', message: ['Fix issue #%d', 59], suffix: '(@klaudiosinani)'}); //=> [task] ☒ complete Fix issue #59 (@klaudiosinani) ``` -------------------------------- ### Logger Methods Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Signale provides various methods for logging messages. These methods can accept a string message, multiple string arguments, an error object, or a message object for custom formatting. ```APIDOC ## signale.(message[, message]|messageObj|errorObj) ### Description Logs a message using a specified logger method. Supports various input formats including strings, arrays of strings, error objects, and custom message objects. ### Parameters #### logger - Type: `Function` - Description: Any default or custom logger method. #### message - Type: `String` or `Array` - Description: One or more comma-delimited strings or a formatted string. #### errorObj - Type: `Error Object` - Description: An error object to be logged. #### messageObj - Type: `Object` - Description: An object with `prefix`, `message`, and `suffix` attributes for custom log formatting. ### Request Example ```javascript const signale = require('signale'); signale.success('Successful operation'); signale.error(new Error('Unsuccessful operation')); signale.complete({prefix: '[task]', message: 'Fix issue #59', suffix: '(@klaudiosinani)'}); ``` ### Response Example ``` // For signale.success('Successful operation'): // ✔ success Successful operation // For signale.error(new Error('Unsuccessful operation')): // ✖ error Error: Unsuccessful operation // ... stack trace ... // For signale.complete({...}): // [task] ☒ complete Fix issue #59 (@klaudiosinani) ``` ``` -------------------------------- ### Redirecting Signale Output to Writable Streams Source: https://context7.com/klaudiosinani/signale/llms.txt Redirect all log output to a specified writable stream or an array of streams using the `stream` option. Errors can be configured to log to both a file and stderr. ```javascript const fs = require('fs'); const { Signale } = require('signale'); const logFile = fs.createWriteStream('./app.log', { flags: 'a' }); const logger = new Signale({ // All loggers write to file instead of stdout stream: logFile, types: { error: { // errors go to BOTH file and stderr for immediate visibility stream: [logFile, process.stderr], badge: '✖', color: 'red', label: 'error', logLevel: 'error' } } }); logger.info('Server started on port 3000'); // Written to app.log only logger.error('Unhandled exception thrown'); // Written to app.log AND process.stderr ``` -------------------------------- ### Interactive Mode with Signale Source: https://context7.com/klaudiosinani/signale/llms.txt Use interactive mode for progress indicators and step-by-step status updates. Each new log message overwrites the previous one in the terminal. ```javascript const { Signale } = require('signale'); const spinner = new Signale({ interactive: true, scope: 'build' }); const steps = [ () => spinner.await('[1/3] Installing dependencies...'), () => spinner.await('[2/3] Compiling TypeScript...'), () => spinner.success('[3/3] Build complete!') ]; // Each call overwrites the previous line in a real TTY let i = 0; const tick = setInterval(() => { steps[i++](); if (i === steps.length) clearInterval(tick); }, 800); ``` -------------------------------- ### Manage Timers with Signale Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Measure execution time using `time()` and `timeEnd()`. Timers can be labeled for identification or used without labels, in which case the most recently created unlabeled timer is managed. ```javascript const signale = require('signale'); signale.time('test'); signale.time(); signale.time(); setTimeout(() => { signale.timeEnd(); signale.timeEnd(); signale.timeEnd('test'); }, 500); ``` -------------------------------- ### signale.unscope() Source: https://context7.com/klaudiosinani/signale/llms.txt Clears the scope name on an existing Signale instance in-place, reverting its output to unscoped. ```APIDOC ## `signale.unscope()` — Remove Scope Clears the scope name on an existing instance in-place, reverting it to unscoped output. ### Usage ```js const signale = require('signale'); const logger = signale.scope('worker'); logger.start('Job started'); //=> [worker] › ▶ start Job started logger.unscope(); logger.complete('Job finished'); //=> ☒ complete Job finished ``` ``` -------------------------------- ### TypeScript Usage with Signale Source: https://context7.com/klaudiosinani/signale/llms.txt Utilize Signale with TypeScript for type safety, including custom logger types and autocomplete. The default instance and custom instances are fully typed. ```typescript import signale, { Signale } from 'signale'; import { WritableStream } from 'stream'; // Default instance is fully typed signale.success('Typed log'); signale.error(new Error('Typed error')); // Custom instance — union type tracks custom keys const logger = new Signale<'deploy' | 'rollback'>({ types: { deploy: { badge: '🚀', color: 'green', label: 'deploy', logLevel: 'info' }, rollback: { badge: '⏪', color: 'yellow', label: 'rollback', logLevel: 'warn' } } }); logger.deploy('v2.5.0 → production'); // ✅ type-safe logger.rollback('Reverting to v2.4.0'); // ✅ type-safe // logger.unknown('test'); // ❌ TypeScript error // Timer return types const label: string = logger.time('build'); const result: { label: string; span: number } = logger.timeEnd('build'); ``` -------------------------------- ### Configure Scoped Logger Instance Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Configure a scoped logger to override configurations inherited from its parent instance or package.json. Ensures unique settings for specific scopes. ```javascript // foo.js const signale = require('signale'); signale.config({ displayFilename: true, displayTimestamp: true, displayDate: false }); signale.success('Hello from the Global scope'); function foo() { // `fooLogger` inherits the config of `signale` const fooLogger = signale.scope('foo scope'); // Overrides both `signale` and `package.json` configs fooLogger.config({ displayFilename: true, displayTimestamp: false, displayDate: true }); fooLogger.success('Hello from the Local scope'); } foo(); ``` -------------------------------- ### signale.addSecrets(secrets) Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Adds new sensitive information (secrets) to the Signale instance, which will then be masked in log outputs. ```APIDOC ## signale.addSecrets(secrets) ### Description Adds new secrets/sensitive-information to the targeted Signale instance. ### Parameters #### Path Parameters - **secrets** (Array) - Required - Array holding the secrets/sensitive-information to be filtered out. ### Request Example ```js const signale = require('signale'); signale.addSecrets(['mySensitiveData']); signale.log('User logged in with token: %s', 'mySensitiveData'); //=> $ User logged in with token: [secure] ``` ``` -------------------------------- ### Scope Management Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Manage logger scopes to categorize log messages. Scopes can be chained and cleared. ```APIDOC ## signale.scope(name[, name]) ### Description Defines the scope name(s) for the logger instance. Scopes are used to categorize log output. ### Parameters #### name - Type: `String` - Description: One or more comma-delimited strings representing the scope name(s). ### Request Example ```javascript const signale = require('signale'); const foo = signale.scope('foo'); const fooBar = signale.scope('foo', 'bar'); foo.success('foo'); fooBar.success('foo bar'); ``` ### Response Example ``` // For foo.success('foo'): // [foo] › ✔ success foo // For fooBar.success('foo bar'): // [foo] [bar] › ✔ success foo bar ``` ``` ```APIDOC ## signale.unscope() ### Description Clears the scope name(s) of the current logger instance, reverting to global or parent scope configuration. ### Request Example ```javascript const signale = require('signale'); const foo = signale.scope('foo'); foo.success('foo'); //=> [foo] › ✔ success foo foo.unscope(); foo.success('foo'); //=> ✔ success foo ``` ``` -------------------------------- ### signale.isEnabled() Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Checks if the logging functionality for a specific Signale instance is currently enabled. ```APIDOC ## signale.isEnabled() ### Description Checks whether the logging functionality of a specific instance is enabled. ### Response #### Success Response (200) - **isEnabled** (Boolean) - Returns `true` if logging is enabled, `false` otherwise. ### Request Example ```js const signale = require('signale'); signale.isEnabled(); // => true signale.disable(); signale.isEnabled(); // => false ``` ``` -------------------------------- ### Check if Logging is Enabled with Signale Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Checks and returns a boolean indicating whether the logging functionality of the Signale instance is currently enabled. ```javascript const signale = require('signale'); signale.success('foo'); //=> ✔ success foo signale.isEnabled(); // => true signale.disable(); signale.success('foo'); //=> signale.isEnabled(); // => false ``` -------------------------------- ### Override Default Signale Loggers Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Customize the appearance of default loggers like 'error' and 'success' by providing new configurations for their badges and labels in the 'types' field of the options object. This demonstrates both default and overridden logger behavior. ```javascript const {Signale} = require('signale'); const options = { types: { error: { badge: '!!', label: 'fatal error' }, success: { badge: '++', label: 'huge success' } } }; const signale = new Signale(); signale.error('Default Error Log'); signale.success('Default Success Log'); const custom = new Signale(options); custom.error('Custom Error Log'); custom.success('Custom Success Log'); ``` -------------------------------- ### Disable Logging with Signale Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Disables all logging functionality for the current Signale instance. Logs made after disabling will not be displayed. ```javascript const signale = require('signale'); signale.success('foo'); //=> ✔ success foo signale.disable(); signale.success('foo'); //=> ``` -------------------------------- ### Secrets Filtering with Signale Source: https://context7.com/klaudiosinani/signale/llms.txt Filter sensitive information by providing an array of secrets to the `secrets` option. Secrets are replaced with `[secure]` in all log output. Secrets can be added dynamically or cleared. ```javascript const { Signale } = require('signale'); // Secrets should come from env vars or a secrets manager, never hardcoded const API_KEY = process.env.API_KEY || 'sk-prod-abc123'; const DB_PASS = process.env.DB_PASS || 'hunter2'; const logger = new Signale({ secrets: [API_KEY, DB_PASS] }); logger.info('Connecting with key=%s', API_KEY); //=> ℹ info Connecting with key=[secure] logger.log('DB password: %s', DB_PASS); //=> DB password: [secure] // Child scope inherits secrets const child = logger.scope('auth'); child.success('Authenticated with token %s', API_KEY); //=> [auth] › ✔ success Authenticated with token [secure] // Dynamically add more secrets logger.addSecrets(['my-session-token']); logger.log('session: my-session-token'); //=> session: [secure] // Clear all secrets logger.clearSecrets(); logger.log('session: my-session-token'); //=> session: my-session-token ``` -------------------------------- ### Add Secrets for Masking with Signale Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Adds an array of strings or numbers to be masked in log output. Any subsequent logs containing these values will have them replaced with '[secure]'. ```javascript const signale = require('signale'); signale.log('$ exporting USERNAME=%s', 'klaudiosinani'); //=> $ exporting USERNAME=klaudiosinani signale.addSecrets(['klaudiosinani']); signale.log('$ exporting USERNAME=%s', 'klaudiosinani'); //=> $ exporting USERNAME=[secure] ``` -------------------------------- ### signale.timeEnd([label]) Source: https://github.com/klaudiosinani/signale/blob/master/readme.md Deactivates the timer associated with the given label. If no label is provided, the most recently created timer without a label is deactivated. Returns an object containing the timer label and its total running time. ```APIDOC ## signale.timeEnd([label]) ### Description Deactivates the timer to which the given label corresponds. If no label is provided the most recent timer, that was created without providing a label, will be deactivated. Returns an object `{label, span}` holding the timer label and the total running time. ### Parameters #### Path Parameters - **label** (String) - Optional - Label corresponding to the timer, each timer has its own unique label. ### Response #### Success Response (200) - **label** (String) - The label of the timer that was ended. - **span** (Number) - The total running time of the timer in milliseconds. ### Request Example ```js const signale = require('signale'); signale.time('myLabel'); //=> ▶ myLabel Initialized timer... signale.timeEnd('myLabel'); //=> ◼ myLabel Timer run for: 2ms ``` ``` -------------------------------- ### Remove Scope with `signale.unscope()` Source: https://context7.com/klaudiosinani/signale/llms.txt Call `unscope()` on a Signale instance to remove its current scope, reverting to unscoped output for subsequent log messages. This modifies the instance in-place. ```javascript const signale = require('signale'); const logger = signale.scope('worker'); logger.start('Job started'); //=> [worker] › ▶ start Job started logger.unscope(); logger.complete('Job finished'); //=> ☒ complete Job finished ```