https://github.com/thisguymartin/barebone-logger
Simple Node Logger is a user-friendly logging utility for Node.js, offering multiple levels like debug, info, and error. It enhances log details by allowing custom fields, making it ideal for efficient application monitoring.
https://github.com/thisguymartin/barebone-logger
lightweight logging nodejs simple vite
Last synced: 5 months ago
JSON representation
Simple Node Logger is a user-friendly logging utility for Node.js, offering multiple levels like debug, info, and error. It enhances log details by allowing custom fields, making it ideal for efficient application monitoring.
- Host: GitHub
- URL: https://github.com/thisguymartin/barebone-logger
- Owner: thisguymartin
- Created: 2023-12-27T23:06:18.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-25T00:10:59.000Z (about 2 years ago)
- Last Synced: 2024-04-25T01:59:29.074Z (about 2 years ago)
- Topics: lightweight, logging, nodejs, simple, vite
- Language: HTML
- Homepage: https://thisguymartin.github.io/barebone-logger/
- Size: 180 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🪵 barebone-logger
Simple Node Logger is a lightweight and easy-to-use logging utility for Node.js applications. It provides a straightforward way to log messages at various levels (debug, info, warn, error, fatal) and supports adding custom fields to logs for more detailed information.
## Features
- Simple and intuitive API.
- Supports multiple log levels: debug, info, warn, error, fatal.
- Ability to add custom fields to logs.
- Toggleable debug mode for development environments.
## Installation
To install Simple Node Logger, use npm:
```bash
npm install simple-node-logger
```
Or using yarn:
```bash
yarn add simple-node-logger
```
## Usage
### Basic Logging
Here's a quick example to get you started:
```javascript
const Logger = require('simple-node-logger');
// Create a new logger instance
const logger = new Logger();
// Logging messages at different levels
logger.debug('This is a debug message');
logger.info('This is an info message');
logger.warn('This is a warning message');
logger.error('This is an error message');
logger.fatal('This is a fatal message');
```
### Advanced Logging with Custom Fields
To add more context to your logs, you can use withField and withFields methods:
```javascript
// Adding a single custom field
const logWithUser = logger.withField('userId', '12345');
logWithUser.info('User login event');
// Adding multiple custom fields
const response = { status: 404, body: 'Not Found' };
logger.withFields({ response }).error('Response code from OEPricingMultipleV3 API was not 200');
// Chaining fields for more detailed logs
logger
.withField('userId', '12345')
.withField('transactionId', 'abcde12345')
.info('Transaction completed');
```
## API Reference
### `logger.debug(message)`
Logs a debug message.
### `logger.info(message)`
Logs an informational message.
### `logger.warn(message)`
Logs a warning message.
### `logger.error(message)`
Logs an error message.
### `logger.fatal(message)`
Logs a fatal error message.
### `logger.withField(key, value)`
Creates a new logger entry with a field.
### `logger.withFields(fields)`
Creates a new logger entry with multiple fields.
### `logger.setDebug(enabled)`
Enables or disables debug mode.