### Enable File Logging with @starkow/logger Source: https://context7.com/nitreojs/logger/llms.txt Details how to enable persistent logging to a file using `Logger.config.setFilePath`. It shows how to configure the file path and provides an example of the file output format. ```typescript import { resolve } from 'node:path' import { Logger, LogLevel } from '@starkow/logger' // Enable file logging Logger.config.setFilePath(resolve(__dirname, 'app.log')) Logger.config.setLogLevel(LogLevel.Error) const log = Logger.create('api') log('Request received') log.info('Processing request', { endpoint: '/users', method: 'GET' }) log.warn('Rate limit approaching') log.error('Request failed', { status: 500 }) // File output (app.log): // 2024-01-15T10:30:45.123Z [api] Request received // 2024-01-15T10:30:45.125Z [api] INFO Processing request {"endpoint":"/users","method":"GET"} // 2024-01-15T10:30:45.126Z [api] WARN Rate limit approaching // 2024-01-15T10:30:45.127Z [api] ERROR Request failed {"status":500} // Disable file logging Logger.config.resetFilePath() ``` -------------------------------- ### Log Messages with Data Source: https://github.com/nitreojs/logger/blob/lord/README.md Provides examples of using the static logging methods to log various types of data, including strings, objects, and errors. ```javascript Logger.log('foo', { bar: 'baz' }) Logger.error('error!') Logger.debug({ type: 'paid', amount: 13.49 }) ``` -------------------------------- ### Initialize Logger with Colors Source: https://github.com/nitreojs/logger/blob/lord/README.md Shows how to initialize a logger instance with specific colors and text styles applied to its prefix. ```javascript Logger.create('bot', Color.Green, TextStyle.Underline)('started!') ``` -------------------------------- ### Logger Initialization and Basic Usage Source: https://github.com/nitreojs/logger/blob/lord/README.md Demonstrates how to create a logger instance and use it for basic logging with custom text and colors. ```APIDOC ## Logger Initialization and Basic Usage ### Description This section covers the basic initialization of the logger and its usage for logging messages with customizable text and colors. ### Method `Logger.create(name: string, ...colors: AnyColor[])` ### Endpoint N/A (Client-side library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { Logger, Color, TextStyle } from '@starkow/logger' const log = Logger.create('foo') // log will be given random yet deterministic color log('bar', Logger.color('baz', Color.Red, TextStyle.Bold), ':)' ``` ### Response #### Success Response (200) N/A (Client-side library) #### Response Example N/A ``` -------------------------------- ### Colorize Text Source: https://github.com/nitreojs/logger/blob/lord/README.md Illustrates how to apply specific colors and background colors to a given text string. ```javascript const coloredFoo = Logger.color('foo', Color.Magenta, BackgroundColor.White) Logger.log(coloredFoo) ``` -------------------------------- ### Initialize and Use Logger Instance Source: https://github.com/nitreojs/logger/blob/lord/README.md Demonstrates how to create a logger instance with a specific name, which will have a deterministic color. It also shows how to log messages with colored and styled text. ```typescript import { Logger, Color, TextStyle } from '@starkow/logger' const log = Logger.create('foo') // log will be given random yet deterministic color log('bar', Logger.color('baz', Color.Red, TextStyle.Bold), ':)' ) ``` -------------------------------- ### Utility Methods Source: https://github.com/nitreojs/logger/blob/lord/README.md Describes utility functions provided by the logger for prefix generation and text colorization. ```APIDOC ## Utility Methods ### Description This section covers utility methods provided by the logger for creating prefixes and colorizing text. ### `Logger.prefix(name: string, ...colors: AnyColor[])` > Generates a formatted prefix string for log messages. *Returns: `string`* *Example:* ```js const prefix = Logger.prefix('server', Color.Cyan) Logger.log(prefix, 'started!') ``` ### `Logger.color(text: string, ...colors: AnyColor[])` > Colorizes the given text with specified colors and text styles. *Returns: `string`* *Example:* ```js const coloredFoo = Logger.color('foo', Color.Magenta, BackgroundColor.White) Logger.log(coloredFoo) ``` ``` -------------------------------- ### Logger Instance Methods Source: https://github.com/nitreojs/logger/blob/lord/README.md Details the various methods available on a logger instance, including general logging, error, warn, debug, and info methods. ```javascript const log = Logger.create('logger') log( 'foo', ['bar', 13.37]) log.log('foo', ['bar', 13.37]) log('1') log.update('2') log.update('3') log.error('failed!') log.warn('something is about to crash!') log.debug({ 42: 'the truth' }) log.info('this log is very mandatory keep listening to me i swear') ``` -------------------------------- ### File Logging Configuration Source: https://github.com/nitreojs/logger/blob/lord/README.md Shows how to configure the logger to write log messages to a specified file. ```APIDOC ## File Logging Configuration ### Description This section explains how to enable and configure file logging, directing all log output to a specified file. ### Method `Logger.config.setFilePath(filePath: string)` ### Endpoint N/A (Client-side library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { resolve } from 'node:path' import { Logger } from '@starkow/logger' Logger.config.setFilePath(resolve(__dirname, 'epic.log')) Logger.create('this will be logged')('into a file!', { 42: true }) ``` ### Response #### Success Response (200) N/A (Client-side library) #### Response Example *File `epic.log` content example:* ```log 2023-10-05T22:47:16.630Z [this will be logged] into a file! {"42":true} ``` ``` -------------------------------- ### Log Levels Configuration Source: https://github.com/nitreojs/logger/blob/lord/README.md Explains how to configure and use different log levels to control the verbosity of the logger output. ```APIDOC ## Log Levels Configuration ### Description This section details the different log levels available and how to configure the logger to only display messages up to a certain level. ### Priority of Log Levels: 1. `LogLevel.Generic` - `log(...)`, `log.log(...)` 2. `LogLevel.Info` - `log.info(...)` + all the above 3. `LogLevel.Debug` - `log.debug(...)` + all the above 4. `LogLevel.Warn` - `log.warn(...)` + all the above 5. `LogLevel.Error` - `log.error(...)` + all the above *Default log level is `LogLevel.Error`* ### Method `Logger.config.setLogLevel(level: LogLevel)` ### Endpoint N/A (Client-side library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { Logger, LogLevel } from '@starkow/logger' Logger.config.setLogLevel(LogLevel.Info) // only Info and lower will be logged const log = Logger.create('@starkow/logger') log('is cool!') log.info('is the best!') log.debug('sucks') // we dont want this to be logged so we chose LogLevel.Info instead of LogLevel.Debug ``` ### Response #### Success Response (200) N/A (Client-side library) #### Response Example N/A ``` -------------------------------- ### Generate Logger Prefix Source: https://github.com/nitreojs/logger/blob/lord/README.md Demonstrates how to generate a formatted prefix string for a logger, which can then be used in log messages. ```javascript const prefix = Logger.prefix('server', Color.Cyan) Logger.log(prefix, 'started!') ``` -------------------------------- ### Logger Instance Methods Source: https://github.com/nitreojs/logger/blob/lord/README.md Details the various methods available on a logger instance, including logging, updating, and error handling. ```APIDOC ## Logger Instance Methods ### Description This section provides a reference for the methods available on a logger instance created using `Logger.create()`. ### `LoggerInstance` #### `(...data: any[]): void`, `log(...data: any[]): void` Logs messages using the generic log level. *Example:* ```js log( 'foo', ['bar', 13.37]) log.log('foo', ['bar', 13.37]) ``` #### `update(...): void` Updates the last log line. Useful for progress indicators or dynamic status messages. *Example:* ```js log('1') log.update('2') log.update('3') ``` #### `error(...): void` Logs an error message. *Example:* ```js log.error('failed!') ``` #### `warn(...): void` Logs a warning message. *Example:* ```js log.warn('something is about to crash!') ``` #### `debug(...): void` Logs a debug message. *Example:* ```js log.debug({ 42: 'the truth' }) ``` #### `info(...): void` Logs an informational message. *Example:* ```js log.info('this log is very mandatory keep listening to me i swear') ``` ``` -------------------------------- ### Alternative Logger Imports Source: https://github.com/nitreojs/logger/blob/lord/README.md Shows alternative ways to import the Logger class and its associated color and text style utilities. ```typescript import { Logger } from '@starkow/logger' import { Color, TextStyle } from '@starkow/logger/colors' ``` -------------------------------- ### Configure and Use File Logging Source: https://github.com/nitreojs/logger/blob/lord/README.md Demonstrates how to configure the logger to write logs to a specified file. All subsequent log messages will be appended to this file. ```typescript import { resolve } from 'node:path' import { Logger } from '@starkow/logger' Logger.config.setFilePath(resolve(__dirname, 'epic.log')) Logger.create('this will be logged')('into a file!', { 42: true }) ``` -------------------------------- ### Importing Color and Style Enums from @starkow/logger Source: https://context7.com/nitreojs/logger/llms.txt Demonstrates how to import enums for colors, backgrounds, text styles, and log levels from the @starkow/logger library. It shows both standard imports and an alternative import path for color-related enums. ```typescript import { Logger, Color, BackgroundColor, TextStyle, LogLevel } from '@starkow/logger' // Alternative import for colors only import { Color, TextStyle } from '@starkow/logger/colors' // All available foreground colors const colors = { black: Color.Black, // 30 red: Color.Red, // 31 green: Color.Green, // 32 yellow: Color.Yellow, // 33 blue: Color.Blue, // 34 magenta: Color.Magenta, // 35 cyan: Color.Cyan, // 36 white: Color.White, // 37 gray: Color.Gray // 90 } // All available background colors const backgrounds = { black: BackgroundColor.Black, // 40 red: BackgroundColor.Red, // 41 green: BackgroundColor.Green, // 42 yellow: BackgroundColor.Yellow, // 43 blue: BackgroundColor.Blue, // 44 magenta: BackgroundColor.Magenta, // 45 cyan: BackgroundColor.Cyan, // 46 white: BackgroundColor.White // 47 } // All available text styles const styles = { bold: TextStyle.Bold, // 1 dim: TextStyle.Dim, // 2 italic: TextStyle.Italic, // 3 underline: TextStyle.Underline, // 4 inverse: TextStyle.Inverse, // 7 hidden: TextStyle.Hidden, // 8 strikethrough: TextStyle.Strikethrough // 9 } // All log levels (in priority order) const levels = { generic: LogLevel.Generic, // 0 - lowest priority info: LogLevel.Info, // 1 debug: LogLevel.Debug, // 2 warn: LogLevel.Warn, // 3 error: LogLevel.Error // 4 - highest priority } ``` -------------------------------- ### Create Named Logger Instance with @starkow/logger Source: https://context7.com/nitreojs/logger/llms.txt Demonstrates creating logger instances with automatic deterministic colors or custom colors and text styles. It also shows how to use different log levels like info, debug, warn, and error. ```typescript import { Logger, Color, TextStyle } from '@starkow/logger' // Create logger with automatic deterministic color const log = Logger.create('my-app') log('Application starting...') log('Processing items:', [1, 2, 3]) // Create logger with custom colors const serverLog = Logger.create('server', Color.Green, TextStyle.Bold) serverLog('Server started on port 3000') // Use different log levels const dbLog = Logger.create('database') dbLog.info('Connected to database') dbLog.debug({ query: 'SELECT * FROM users', time: '12ms' }) dbLog.warn('Connection pool running low') dbLog.error('Failed to execute query:', new Error('Timeout')) // Output: // my-app Application starting... // my-app Processing items: [ 1, 2, 3 ] // server Server started on port 3000 // database Connected to database // database { query: 'SELECT * FROM users', time: '12ms' } // database Connection pool running low // database Failed to execute query: Error: Timeout ``` -------------------------------- ### Configure Log Level Filtering with @starkow/logger Source: https://context7.com/nitreojs/logger/llms.txt Explains how to set the minimum log level for output using `Logger.config.setLogLevel`. It details the log level hierarchy and demonstrates filtering behavior. ```typescript import { Logger, LogLevel } from '@starkow/logger' // Set log level to Info - enables Generic and Info, disables Debug/Warn/Error Logger.config.setLogLevel(LogLevel.Info) const log = Logger.create('app') log('This will be logged') // Generic - logged log.info('This will be logged') // Info - logged log.debug('This will NOT be logged') // Debug - filtered out log.warn('This will NOT be logged') // Warn - filtered out log.error('This will NOT be logged') // Error - filtered out // Set log level to Error to see all logs Logger.config.setLogLevel(LogLevel.Error) log.debug('Now this is logged') // Debug - logged log.error('And this too') // Error - logged // Reset to default Logger.config.resetLogLevel() ``` -------------------------------- ### Configure and Use Log Levels Source: https://github.com/nitreojs/logger/blob/lord/README.md Explains how to set the global log level to control which messages are displayed. Only messages with a priority equal to or higher than the set level will be logged. ```typescript import { Logger, LogLevel } from '@starkow/logger' Logger.config.setLogLevel(LogLevel.Info) // only Info and lower will be logged const log = Logger.create('@starkow/logger') log('is cool!') log.info('is the best!') log.debug('sucks') // we dont want this to be logged so we chose LogLevel.Info instead of LogLevel.Debug ``` -------------------------------- ### Logger.create - Create a Named Logger Instance Source: https://context7.com/nitreojs/logger/llms.txt Creates a new logger instance with a specified name and optional colors. If no colors are provided, a deterministic RGB color is generated based on the name hash. The returned logger instance is callable and includes methods for different log levels. ```APIDOC ## Logger.create - Create a Named Logger Instance ### Description Creates a new logger instance with a specified name and optional colors. If no colors are provided, a deterministic RGB color is generated based on the name hash, ensuring the same name always produces the same color. The returned logger instance is callable and includes methods for different log levels. ### Method Static method of the Logger class. ### Endpoint N/A (This is a library function, not a network endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { Logger, Color, TextStyle } from '@starkow/logger' // Create logger with automatic deterministic color const log = Logger.create('my-app') log('Application starting...') log('Processing items:', [1, 2, 3]) // Create logger with custom colors const serverLog = Logger.create('server', Color.Green, TextStyle.Bold) serverLog('Server started on port 3000') // Use different log levels const dbLog = Logger.create('database') dbLog.info('Connected to database') dbLog.debug({ query: 'SELECT * FROM users', time: '12ms' }) dbLog.warn('Connection pool running low') dbLog.error('Failed to execute query:', new Error('Timeout')) ``` ### Response #### Success Response (200) N/A (This function returns a logger instance, not a network response) #### Response Example ```typescript // Logger instance returned // Example usage output: // my-app Application starting... // my-app Processing items: [ 1, 2, 3 ] // server Server started on port 3000 // database Connected to database // database { query: 'SELECT * FROM users', time: '12ms' } // database Connection pool running low // database Failed to execute query: Error: Timeout ``` ``` -------------------------------- ### Generate Colored Prefix String with Logger.prefix Source: https://context7.com/nitreojs/logger/llms.txt Generates a colored prefix string that can be used with static logging methods. Useful when you need manual control over log formatting while maintaining consistent prefix styling. Supports combining multiple prefixes. ```typescript import { Logger, Color, TextStyle } from '@starkow/logger' // Create reusable prefixes const serverPrefix = Logger.prefix('server', Color.Cyan) const dbPrefix = Logger.prefix('database', Color.Magenta) const cachePrefix = Logger.prefix('cache', Color.Yellow) // Use with static log methods Logger.log(serverPrefix, 'Starting HTTP server...') Logger.log(dbPrefix, 'Connecting to PostgreSQL...') Logger.log(cachePrefix, 'Initializing Redis connection...') Logger.error(serverPrefix, 'Failed to bind to port 3000') Logger.warn(dbPrefix, 'Slow query detected:', { duration: '5000ms' }) Logger.info(cachePrefix, 'Cache hit rate:', '95%') // Combine multiple prefixes Logger.log(serverPrefix, Logger.prefix('GET', Color.Green), '/api/users', '200 OK') Logger.log(serverPrefix, Logger.prefix('POST', Color.Blue), '/api/users', '201 Created') ``` -------------------------------- ### Direct Console Output with Static Logging Methods Source: https://context7.com/nitreojs/logger/llms.txt Provides static methods (`log`, `error`, `warn`, `info`, `debug`) for direct console output without creating a named instance. These map directly to their corresponding console methods and do not support file logging or log level filtering. Can be combined with colorized text. ```typescript import { Logger, Color } from '@starkow/logger' // Direct logging without prefix Logger.log('Simple log message') Logger.error('Error occurred:', { code: 'E001', message: 'Connection failed' }) Logger.warn('Deprecation warning: use newMethod() instead') Logger.info('Server info:', { version: '2.3.1', uptime: '24h' }) Logger.debug('Debug data:', { requestId: 'abc123', payload: { user: 1 } }) // Combine with colorized text Logger.log( Logger.color('[INFO]', Color.Cyan), 'Application initialized in', Logger.color('145ms', Color.Green) ) // Output uses respective console methods: // console.log() for Logger.log() // console.error() for Logger.error() (writes to stderr) // console.warn() for Logger.warn() // console.info() for Logger.info() // console.debug() for Logger.debug() ``` -------------------------------- ### Logger.config.setFilePath - Enable File Logging Source: https://context7.com/nitreojs/logger/llms.txt Configures a file path for persistent logging. When enabled, all log output is also written to the specified file with timestamps and log level prefixes. File logs are stored in a machine-readable format with ISO timestamps. ```APIDOC ## Logger.config.setFilePath - Enable File Logging ### Description Configures a file path for persistent logging. When enabled, all log output is also written to the specified file with timestamps and log level prefixes. File logs are stored in a machine-readable format with ISO timestamps. ### Method Static method of the Logger.config object. ### Endpoint N/A (This is a library function, not a network endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { resolve } from 'node:path' import { Logger, LogLevel } from '@starkow/logger' // Enable file logging Logger.config.setFilePath(resolve(__dirname, 'app.log')) Logger.config.setLogLevel(LogLevel.Error) const log = Logger.create('api') log('Request received') log.info('Processing request', { endpoint: '/users', method: 'GET' }) log.warn('Rate limit approaching') log.error('Request failed', { status: 500 }) // Disable file logging Logger.config.resetFilePath() ``` ### Response #### Success Response (200) N/A (This function configures the logger and does not return a value) #### Response Example ```text // File output (app.log): // 2024-01-15T10:30:45.123Z [api] Request received // 2024-01-15T10:30:45.125Z [api] INFO Processing request {"endpoint":"/users","method":"GET"} // 2024-01-15T10:30:45.126Z [api] WARN Rate limit approaching // 2024-01-15T10:30:45.127Z [api] ERROR Request failed {"status":500} ``` ``` -------------------------------- ### Update Last Log Line Source: https://github.com/nitreojs/logger/blob/lord/README.md Shows how to update the content of the most recently logged line in the console, useful for progress indicators. ```javascript Logger.log( 'Loading: 9%' ) Logger.updateLog('Loading: 45%' ) Logger.updateLog('Loading: 77%' ) Logger.updateLog('Loading: 100% [Done!]') ``` -------------------------------- ### Colorize Text with ANSI Codes using Logger.color Source: https://context7.com/nitreojs/logger/llms.txt Applies foreground colors, background colors, and text styles to a string using ANSI escape codes. Multiple color and style options can be combined. Returns the colorized string that can be used in any log output. ```typescript import { Logger, Color, BackgroundColor, TextStyle } from '@starkow/logger' // Single color const redText = Logger.color('Error!', Color.Red) Logger.log(redText) // Combined foreground and background const highlight = Logger.color('IMPORTANT', Color.Black, BackgroundColor.Yellow) Logger.log(highlight) // Multiple styles combined const styled = Logger.color('Bold Underlined', Color.Cyan, TextStyle.Bold, TextStyle.Underline) Logger.log(styled) // Use in custom log messages const log = Logger.create('status') log('Build:', Logger.color('SUCCESS', Color.Green, TextStyle.Bold)) log('Tests:', Logger.color('FAILED', Color.Red, TextStyle.Bold), '(3 failures)') // Available Colors: Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, Gray // Available BackgroundColors: Black, Red, Green, Yellow, Blue, Magenta, Cyan, White // Available TextStyles: Bold, Dim, Italic, Underline, Inverse, Hidden, Strikethrough ``` -------------------------------- ### Logger.config.setLogLevel - Configure Log Level Filtering Source: https://context7.com/nitreojs/logger/llms.txt Sets the minimum log level that will be output. Log levels have a priority hierarchy: Generic (1) < Info (2) < Debug (3) < Warn (4) < Error (5). Setting a log level enables that level and all lower priority levels. ```APIDOC ## Logger.config.setLogLevel - Configure Log Level Filtering ### Description Sets the minimum log level that will be output. Log levels have a priority hierarchy: Generic (1) < Info (2) < Debug (3) < Warn (4) < Error (5). Setting a log level enables that level and all lower priority levels. The default log level is Error, which enables all levels. ### Method Static method of the Logger.config object. ### Endpoint N/A (This is a library function, not a network endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { Logger, LogLevel } from '@starkow/logger' // Set log level to Info - enables Generic and Info, disables Debug/Warn/Error Logger.config.setLogLevel(LogLevel.Info) const log = Logger.create('app') log('This will be logged') // Generic - logged log.info('This will be logged') // Info - logged log.debug('This will NOT be logged') // Debug - filtered out log.warn('This will NOT be logged') // Warn - filtered out log.error('This will NOT be logged') // Error - filtered out // Set log level to Error to see all logs Logger.config.setLogLevel(LogLevel.Error) log.debug('Now this is logged') // Debug - logged log.error('And this too') // Error - logged // Reset to default Logger.config.resetLogLevel() ``` ### Response #### Success Response (200) N/A (This function configures the logger and does not return a value) #### Response Example N/A ``` -------------------------------- ### Update Last Log Line with Logger.updateLog / log.update Source: https://context7.com/nitreojs/logger/llms.txt Replaces the last logged line with new content, useful for progress indicators and status updates. The static `Logger.updateLog` method updates raw text, while instance `log.update` includes the logger prefix automatically. Supports parameters to control line clearing. ```typescript import { Logger } from '@starkow/logger' // Static method for raw progress updates Logger.log('Downloading: 0%') Logger.updateLog('Downloading: 25%') Logger.updateLog('Downloading: 50%') Logger.updateLog('Downloading: 75%') Logger.updateLog('Downloading: 100% [Complete]') // Instance method with automatic prefix const log = Logger.create('build') log('Compiling...') log.update('Compiling: 50%') log.update('Compiling: 100%') log.update('Build complete!') // With params to control line clearing log('Step 1') log.update({ clearLastLine: false }, 'Step 2') // Keeps Step 1 visible log.update({ clearLastLine: true }, 'Step 3') // Replaces Step 2 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.