1.0.0 • Published 3 years ago
@codrjs/logger v1.0.0
@codrjs/logger
Purpose
This module is to help facilitate creating and managing multiple winston loggers on the global level of each micro-service within Codr.
Getting started
Important! By default, all loggers log to a logs/combined.log file and the console. There is no need to add these additional transports.
Logging levels:
- error
- warn
- info
- http
- verbose
- debug
Log structure:
All logs in every micro-service should look like this:
logs/
[service]/
all.log
debug.log
...
combined.logInstalling the package
Install the package from the npm registry. You do not need to install winston. This package SHOULD take care of all logging needs.
yarn add @codrjs/loggerInside the micro-service, you can get create a logger for each internal service you want to seperate.
/* Import the health package */
import Logger, { transports } from "@codrjs/logger";
const logger = Logger.add("Service 1", [
new transports.File({
filename: "logs/service-1/all.log",
}),
new transports.File({
filename: "logs/service-1/debug.log",
level: "debug",
}),
]);
const otherLogger = Logger.add("Service 2", [
new transports.File({
filename: "logs/service-2/all.log",
}),
new transports.File({
filename: "logs/service-2/debug.log",
level: "debug",
}),
]);
logger.info("Hello world!");
logger.debug("I'm a debug message");
otherLogger.info("Hello world!");
otherLogger.debug("I'm a debug message");
/**
Outputs:
logs/combined.log
2023-02-19 11:33:26:3326 [Service 1] [info] Hello world
2023-02-19 11:33:26:3326 [Service 2] [info] Hello world
logs/service-1/all.log
2023-02-19 11:33:26:3326 [Service 1] [info] Hello world
logs/service-1/debug.log
2023-02-19 11:33:26:3326 [Service 1] [debug] I'm a debug message
logs/service-2/all.log
2023-02-19 11:33:26:3326 [Service 2] [info] Hello world
logs/service-2/debug.log
2023-02-19 11:33:26:3326 [Service 2] [debug] I'm a debug message
*/Todo:
- Implement daily rotating logs
Contributing
# Clone the repo
git clone git@github.com:CodrJS/logger.git
# Install yarn if you don't have it already
npm install -g yarn
# Install dependencies, build, and test the code
yarn install
yarn build
yarn test1.0.0
3 years ago