### Install @rabbit-company/logger Package Source: https://github.com/rabbit-company/logger-js/blob/main/README.md Provides commands for installing the `@rabbit-company/logger` package using popular Node.js package managers: npm, yarn, and pnpm. ```bash # npm npm install @rabbit-company/logger # yarn yarn add @rabbit-company/logger # pnpm pnpm add @rabbit-company/logger ``` -------------------------------- ### Initialize and Use Logger for Basic and Structured Logging Source: https://github.com/rabbit-company/logger-js/blob/main/README.md Demonstrates how to import and initialize the `Logger` with a default console transport. It shows examples of simple info logs, structured error logging with metadata, dynamic log level setting, and audit logging. ```javascript import { Logger, Levels } from "@rabbit-company/logger"; // Create logger with default console transport const logger = new Logger({ level: Levels.DEBUG, // Show DEBUG and above }); // Simple log logger.info("Application starting..."); // Structured logging logger.error("Database connection failed", { error: "Connection timeout", attempt: 3, db: "primary", }); // Dynamic log levels logger.log(Levels.WARN, "High memory usage detected", { usage: "85%" }); // Audit logging logger.audit("User login", { userId: "usr_123", ip: "192.168.1.100", }); ``` -------------------------------- ### Custom Console Transport Format Examples Source: https://github.com/rabbit-company/logger-js/blob/main/README.md Illustrates various ways to customize the output format of the `ConsoleTransport` using different datetime, type, message, and metadata placeholders. ```javascript import { ConsoleTransport } from "@rabbit-company/logger"; // Custom format examples new ConsoleTransport("[{datetime-local}] {type} {message} {metadata}"); new ConsoleTransport("{time} | {type} | {message} | {metadata}", false); new ConsoleTransport("EPOCH:{ms} - {message} - {metadata}"); ``` -------------------------------- ### Apply Custom Formatting to Console Transport in JavaScript Source: https://github.com/rabbit-company/logger-js/blob/main/README.md This example illustrates how to apply a custom log message format to the `ConsoleTransport`. It allows defining a string pattern using placeholders like `{type}`, `{date}`, `{message}`, and `{metadata}`, and also shows how to disable console colors. ```javascript new ConsoleTransport( "{type} - {date} - {message} - {metadata}", // Custom format false // Disable colors ); ``` -------------------------------- ### ConsoleTransport Format String Placeholders Reference Source: https://github.com/rabbit-company/logger-js/blob/main/README.md Lists all available placeholders that can be used within the format string of the `ConsoleTransport` for customizing log output. Includes options for UTC and local time, log content, and metadata. ```APIDOC ConsoleTransport Format String Placeholders: UTC Formats: {iso}: Full ISO-8601 (2023-11-15T14:30:45.123Z) {datetime}: Simplified (2023-11-15 14:30:45) {date}: Date only (2023-11-15) {time}: Time only (14:30:45) {utc}: UTC string (Wed, 15 Nov 2023 14:30:45 GMT) {ms}: Milliseconds since epoch Local Time Formats: {datetime-local}: Local datetime (2023-11-15 14:30:45) {date-local}: Local date only (2023-11-15) {time-local}: Local time only (14:30:45) {full-local}: Complete local string with timezone Log Content: {type}: Log level (INFO, ERROR, etc.) {message}: The log message Metadata Placeholders: {metadata}: JSON-stringified metadata (if provided) {metadata-ml}: Multi-line JSON-formatted metadata (if provided) ``` -------------------------------- ### Log Levels Reference Source: https://github.com/rabbit-company/logger-js/blob/main/README.md Defines the eight severity levels available in the `@rabbit-company/logger` library, from `ERROR` to `SILLY`, along with their descriptions and typical use cases. ```APIDOC Levels: ERROR: Critical errors (System failures, unhandled exceptions) WARN: Potential issues (Deprecations, rate limiting) AUDIT: Security events (Logins, permission changes) INFO: Important runtime information (Service starts, config changes) HTTP: HTTP traffic (Request/response logging) DEBUG: Debug information (Flow tracing, variable dumps) VERBOSE: Very detailed information (Data transformations) SILLY: Extremely low-level information (Inner loop logging) ``` -------------------------------- ### Configure Logger with Grafana Loki Transport Source: https://github.com/rabbit-company/logger-js/blob/main/README.md Illustrates how to initialize a `LokiTransport` for sending logs to Grafana Loki. Configuration options include the Loki URL, static labels, basic authentication credentials, batching parameters (size and timeout), maximum queue size, and debug mode for transport errors. ```javascript import { LokiTransport } from "@rabbit-company/logger"; const lokiTransport = new LokiTransport({ url: "http://localhost:3100", labels: { app: "test", env: process.env.NODE_ENV, }, basicAuth: { username: process.env.LOKI_USER, password: process.env.LOKI_PASS, }, batchSize: 50, // Send batches of 50 logs batchTimeout: 5000, // Max 5s wait per batch maxQueueSize: 10000, // Keep max 10,000 logs in memory debug: true, // Log transport errors }); const logger = new Logger({ transports: [lokiTransport], }); ``` -------------------------------- ### Configure Logger with NDJSON Transport Source: https://github.com/rabbit-company/logger-js/blob/main/README.md Demonstrates how to set up the `Logger` with an `NDJsonTransport` to capture logs in a newline-delimited JSON format, and how to retrieve the accumulated log data programmatically. ```javascript import { NDJsonTransport } from "@rabbit-company/logger"; const ndjsonTransport = new NDJsonTransport(); const logger = new Logger({ transports: [ndjsonTransport], }); // Get accumulated logs console.log(ndjsonTransport.getData()); ``` -------------------------------- ### Configure Logger with Custom Console Transport Source: https://github.com/rabbit-company/logger-js/blob/main/README.md Shows how to explicitly configure the `Logger` to use a `ConsoleTransport` with a specific format string and enable or disable colored output. ```javascript import { ConsoleTransport } from "@rabbit-company/logger"; const logger = new Logger({ transports: [ new ConsoleTransport( "[{time-local}] {type} {message} {metadata}", // Custom format true // Enable colors ), ], }); ``` -------------------------------- ### Configure and Use Syslog Transport in JavaScript Source: https://github.com/rabbit-company/logger-js/blob/main/README.md This snippet demonstrates how to configure and use the `SyslogTransport` with the `@rabbit-company/logger` library. It shows options for host, port, protocol (UDP, TCP, TLS), facility, app name, and protocol version, including TLS options for secure connections. The transport supports automatic reconnection, message queuing, and compliance with RFC 3164/5424. ```javascript import { SyslogTransport } from "@rabbit-company/logger"; const syslogTransport = new SyslogTransport({ host: "syslog.example.com", port: 514, protocol: "udp", // 'udp', 'tcp', or 'tcp-tls' facility: 16, // local0 facility appName: "my-app", protocolVersion: 5424, // 3164 (BSD) or 5424 (modern) tlsOptions: { ca: fs.readFileSync("ca.pem"), rejectUnauthorized: true, }, maxQueueSize: 2000, // Max queued messages during outages debug: true // Log connection status }); const logger = new Logger({ transports: [syslogTransport] }); ``` -------------------------------- ### Dynamically Manage Logger Transports and Levels in JavaScript Source: https://github.com/rabbit-company/logger-js/blob/main/README.md This snippet demonstrates how to dynamically add and remove transports from a `Logger` instance, and how to change its global log level. It shows methods like `addTransport`, `removeTransport`, and `setLevel` for flexible runtime control over logging behavior. ```javascript const lokiTransport = new LokiTransport({ /* config */ }); const logger = new Logger(); // Add transport dynamically logger.addTransport(lokiTransport); // Remove transport logger.removeTransport(lokiTransport); // Change log level logger.setLevel(Levels.VERBOSE); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.