Winstan.js is an Open source Winston setup wrapper library for easier logging with less code.
- Only 1 small dependency to check inputs variables
- Very lightweight
- Thoroughly tested
- Works in Javascript and Typescript
- Can be used as EcmaScrypt module
- Written in Typescript
- node: 22
This is the oldest targeted versions. The library should work properly on older versions of Node.js but we do not support it officially.
$ npm i @dwtechs/winstan
import { log } from "@dwtechs/winstan";
log.error(`App cannot start: ${err.msg}`);
log.info(`App started on port : ${PORT}`);
log.debug(`UpdateOne(user=${JSON.stringify(users)})`);
Winstan reduces log levels to four :
- error,
- warn,
- info,
- debug
Winstan will start with the following default configuration :
let defaultSN = "";
let defaultTZ = "europe/paris";
let defaultLocale = "fr-FR"
let defaultNodeEnv = "development";
DefaultSN is the service name. (Or the application name) If provided, it will appear at the beginning of every log. It is useful in a multi-service or multi-application monitoring tool.
You can configure Winstan using 2 methods :
Four environment variables may be used by Winstan :
example :
LOCALE="en-EN"
TZ="UTC"
NODE_ENV="production"
SERVICE_NAME="ms_user"
These environment variables will update the default values of the lib at start up. So you do not need to init the library in the code.
import { log } from "@dwtechs/winstan";
log.info(`App started on port : ${PORT}`);
TZ is the timezone configuration to set time to your region.
This method will override ENV variables.
import { log, init } from "@dwtechs/winstan";
const options = {
timeZone: "UTC",
locale: "fr-FR",
serviceName: "ms_user",
level: "debug"
}
init(options);
log.info(`App started on port : ${PORT}`);
Possible values for NODE_ENV environment variable are "production" and "prod". Those values will set Winstan log level to info. Any other value (like "dev" or "development") will set the log level to debug
export type Levels = 'error'|'warn'|'info'|'debug';
export type Options = {
timeZone: string;
locale: string;
serviceName: string;
level: Levels;
};
init(options: Options): void {}
log(size: number): number {}
Winstan comes with a utility plugin for Express.js.
This plugin will log the time it took to process a request.
$ npm i @dwtechs/winstan-plugin-express-perf
import express from "express";
import perf from '@dwtechs/winstan-plugin-express-perf';
const app = express();
app.use(express.json());
// performance measurement starts for any call to the following routes
app.use(perf.start);
app.use("/", route);
// Performance measurement ends
app.use(perf.end);
Winstan.js is still in development and we would be glad to get all the help you can provide. To contribute please read contributor.md for detailed installation guide.
Purpose | Choice | Motivation |
---|---|---|
repository | Github | hosting for software development version control using Git |
package manager | npm | default node.js package manager |
language | TypeScript | static type checking along with the latest ECMAScript features |
module bundler | Rollup | advanced module bundler for ES6 modules |
unit testing | Jest | delightful testing with a focus on simplicity |