Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
advanced-console-log
Advanced tools
Advanced Console Log (ACL), available as the `advanced-console-log` NPM package, is a lightweight logging module for Node.js applications. It supports console and file logging with various levels, colors, and additional features such as memory usage track
Advanced Console Log (ACL), available as the advanced-console-log
NPM package, is a lightweight logging module for Node.js applications. It supports console and file logging with various levels, colors, and additional features such as memory usage tracking and caller information. ACL prioritizes performance by using lazy loading, ensuring efficient resource management.
debug
, log
, info
, warn
, error
, fatal
) to categorize and prioritize log messages.time
, timeEnd
, startTimer
, stopTimer
).trace
method, similar to console.trace
.dir
method for pretty printing complex objects similar to console.dir
.This logging module utilizes the following built-in Node.js modules:
fs
: For file system operations, such as appending log messages to a specified file.path
: Provides utilities for handling and manipulating file paths, ensuring cross-platform compatibility when working with file system operations.util
: Used to format and inspect complex objects for pretty printing in log outputs.process
: Provides access to the current Node.js process, enabling memory usage tracking and process termination.v8
: Retrieves memory heap statistics to track memory usage within the application. Lazy loaded for performance reasons.worker_threads
: Used for worker thread operations in worker mode. Lazy loaded for performance reasons.There are no external dependencies.
To install the advanced-console-log npm module, you can use npm:
npm install advanced-console-log
After installation, import advanced-console-log
into your application using require:
const ACL = require("advanced-console-log");
Then you can get a single instance of ACL (recommended), created with your custom configuration options.
const logger = ACL.getInstance({
logLevel: 1,
});
or create a new ACL instance, using your custom configuration options.
const logger = new ACL({
logLevel: 1,
});
ACL supports a number of different configuration options. Here is another example using additional configuration options:
const logger = ACL.getInstance({
logLevel: 1,
outputFilename: "app.log",
outputFileLogLevel: 2,
includeTimestamps: true,
includeMemoryUsage: true,
generateReport: true,
terminateOnFatal: true,
mode: "async",
});
ACL supports different modes of asynchronous logging to improve performance in high-throughput scenarios.
To enable an asynchronous logging mode, set the mode
configuration option:
const logger = ACL.getInstance({
mode: "async",
});
Once created, you can use the logger to log messages at various levels:
logger.info("This is an info message");
logger.warn("This is a warning message");
logger.error("This is an error message");
You can also use a boolean to control log display.
const showLog = true;
logger.log(showLog, "This is a log message");
If generateReport
is set to true
, you can generate a detailed report at the end of the application.
const logger = ACL.getInstance({
generateReport: true,
});
logger.report();
ACL also supports asynchronous logging e.g., non-blocking operations. You can configure ACL to run in async mode:
const logger = ACL.getInstance({
mode: "async",
});
logger.info("This is an async info message");
logger.error("This is an async error message");
or you can directly call the async versions of log methods if you prefer:
logger.infoAsync("This is an async info message");
logger.errorAsync("This is an async error message");
ACL lets you measure the elapsed time of code execution using timers:
logger.startTimer("Initialization");
// code to measure
logger.stopTimer("Initialization");
Use the dir
method to pretty print complex objects:
const sampleObject = { name: "John", age: 30, location: "New York" };
logger.dir(sampleObject);
dir
method to pretty print complex objects.Contributions to this project are welcome. Please fork the repository and submit a pull request with your changes or improvements.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
Advanced Console Log (ACL), available as the `advanced-console-log` NPM package, is a lightweight logging module for Node.js applications. It supports console and file logging with various levels, colors, and additional features such as memory usage track
We found that advanced-console-log demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.