https://github.com/sheikhmohdnazmulhasan/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.
https://github.com/sheikhmohdnazmulhasan/traillog
debugging logging npm-package
Last synced: over 1 year ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/sheikhmohdnazmulhasan/traillog
- Owner: sheikhmohdnazmulhasan
- Created: 2025-02-18T20:08:20.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-18T20:11:54.000Z (over 1 year ago)
- Last Synced: 2025-03-19T05:47:37.345Z (over 1 year ago)
- Topics: debugging, logging, npm-package
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/traillog
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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 traillog
```
## Usage
First, import the logger from traillog in your JavaScript or TypeScript file:
```javascript
import logger from "traillog";
```
Then, you can use the different logging methods:
```javascript
// 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:
1. `message` (required): The main log message as a string.
2. `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:
```javascript
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:
```javascript
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:
```javascript
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:
```javascript
logger.info("User logged in", { userId: "user123", timestamp: Date.now() });
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.