Package Exports
- traillog
- traillog/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (traillog) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Traillog
Traillog is a simple, colorful logging utility for Node.js applications. It provides an easy way to add formatted, color-coded logs with timestamps and caller information for better debugging and log readability.
Features
- Color-coded log messages using chalk
- Timestamp for each log entry
- Caller's file and line number for easy tracing
- Support for different log levels: SUCCESS, ERROR, WARN, and INFO
- Optional metadata logging in JSON format
Installation
To install Traillog, run the following command in your project directory:
npm install traillogUsage
First, import the logger from traillog in your JavaScript or TypeScript file:
import logger from "traillog";Then, you can use the different logging methods:
// Log a success message
logger.success("Operation completed successfully");
// Log an error message
logger.error("An error occurred", { errorCode: 500 });
// Log a warning message
logger.warn("This is a warning");
// Log an informational message
logger.info("This is an informational message", { user: "John Doe" });Each logging method accepts two parameters:
message(required): The main log message as a string.meta(optional): An object containing additional metadata to be logged.
Output
The log output will be formatted as follows:
[TIMESTAMP] [LOG_LEVEL] (FILE:LINE): MESSAGE
METADATA (if provided)For example:
[2023-05-20T12:34:56.789Z] [SUCCESS] (src/app.ts:42): Operation completed successfully
[2023-05-20T12:34:57.123Z] [ERROR] (src/app.ts:45): An error occurred
{
"errorCode": 500
}API Reference
The logger object exposes four main methods for logging:
logger.success(message, meta?)
Logs a success message in green.
message(string): The success message to log.meta(object, optional): Additional metadata to log.
Example:
logger.success("Data saved successfully", { id: 123 });logger.error(message, meta?)
Logs an error message in red.
message(string): The error message to log.meta(object, optional): Additional metadata to log, such as error details.
Example:
logger.error("Failed to connect to database", { errorCode: "DB_001" });traillog.warn(message, meta?)
Logs a warning message in yellow.
message(string): The warning message to log.meta(object, optional): Additional metadata to log.
Example:
logger.warn("Deprecated function called", { function: "oldMethod" });traillog.info(message, meta?)
Logs an informational message in blue.
message(string): The informational message to log.meta(object, optional): Additional metadata to log.
Example:
logger.info("User logged in", { userId: "user123", timestamp: Date.now() });Contributing
Contributions are welcome! Please feel free to submit a Pull Request.