1.2.2 • Published 4 months ago

perf-async-logger v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Async Logger šŸ“œ

A simple Node.js library to log async functions with error handling and performance tracking.

šŸš€ Features

  • āœ… Automatic logging for async function calls
  • āœ… Error handling with logs
  • āœ… Execution time tracking
  • āœ… Easy to use decorator-based approach

šŸ“¦ Installation

npm install perf-async-logger

šŸ”§ How to Use

1ļøāƒ£ Import the Logger

import { logAsync, Logger, LogLevel } from "perf-async-logger";

2ļøāƒ£ Use the @logAsync Decorator

Apply @logAsync to your async functions:

import { logAsync } from "perf-async-logger";

class MyService { @logAsync async fetchData(value: string): Promise { return Received: ${value}; }

@logAsync
async fetchWithError(): Promise<void> {
    throw new Error("Intentional error");
}

}

const service = new MyService(); service.fetchData("test"); // Logs execution time and success service.fetchWithError(); // Logs error message

šŸ“œ Logger Output

The library logs start time, execution time, and errors:

āœ… Successful function call

INFO 2025-02-21T15:28:37.986Z - Start fetchData with args: "test" 2025-02-21T15:28:37.991Z - End fetchData with result: "Received: test" INFO 2025-02-21T15:28:37.996Z - fetchData executed in 5.679ms

āŒ Error in function

INFO 2025-02-21T15:26:49.260Z - Start fetchWithError with args: 2025-02-21T15:26:49.265Z - fetchWithError executed in 5.052ms with error: Intentional error

āš™ļø Custom Logging

You can manually log messages using the Logger class:

import { Logger, LogLevel } from "perf-async-logger";

Logger.log(LogLevel.INFO, "This is an info message"); Logger.log(LogLevel.ERROR, "Something went wrong!");

šŸ›  Configuration (Optional)

By default, logs are written to log.txt. To change this, set the LOG_FILE environment variable:

export LOG_FILE=custom-log.txt


šŸ“„ License

This project is licensed under the MIT License. šŸ¤ Contributing

Feel free to fork and submit PRs! šŸš€


šŸ“¬ Contact

Created by sawssen Fattahi https://github.com/sawsenFattahi


šŸ†• Updates:

āœ… Added a "How to Use" section with clear steps
āœ… Explained configuration (changing log file name)
āœ… More clarity on error logging and outputs

Let me know if you need any other changes! šŸš€šŸ”„

1.2.2

4 months ago

1.2.1

4 months ago

1.2.0

4 months ago

1.0.10

4 months ago

1.0.8

4 months ago

1.0.6

4 months ago

1.0.4

4 months ago

1.0.2

4 months ago

1.0.0

4 months ago