Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/epegzz/winston-dev-console
Winston@3 console format aimed to improve development UX
https://github.com/epegzz/winston-dev-console
console debug development format formatter inspect logger logging node node-js nodejs pretty winston winston-logger
Last synced: 3 months ago
JSON representation
Winston@3 console format aimed to improve development UX
- Host: GitHub
- URL: https://github.com/epegzz/winston-dev-console
- Owner: epegzz
- License: mit
- Created: 2021-04-04T16:55:53.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-23T22:10:13.000Z (almost 3 years ago)
- Last Synced: 2024-10-12T09:39:02.985Z (4 months ago)
- Topics: console, debug, development, format, formatter, inspect, logger, logging, node, node-js, nodejs, pretty, winston, winston-logger
- Language: TypeScript
- Homepage:
- Size: 1.3 MB
- Stars: 96
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# winston-dev-console
A Winston@3 console format for development (based on [winston-console-format](https://github.com/duccio/winston-console-format)) that aims to improve NodeJS development UX by
* adding the source of the logging statement to the log output
* optimizing readability of each log statement through log statement separation, output colorization and arg pretty printing
## Demo
![](demo.png)
### Real world screenshot:
![](demo2.png)
## Install
```bash
npm install winston @epegzz/winston-dev-console
```or
```bash
yarn add winston @epegzz/winston-dev-console
```## Usage TypeScript
```typescript
import { createLogger, format, transports } from "winston";
import winstonDevConsole from "@epegzz/winston-dev-console";
import util from "util";let log = createLogger({
level: "silly", // or use process.env.LOG_LEVEL
});// Note: You probably only want to use winstonDevConsole during development
log = winstonDevConsole.init(log);
log.add(
winstonDevConsole.transport({
showTimestamps: false,
addLineSeparation: true,
})
);log.silly("Logging initialized");
log.debug("Debug an object", { make: "Ford", model: "Mustang", year: 1969 });
log.verbose("Returned value", { value: util.format });
log.info("Information", {
options: ["Lorem ipsum", "dolor sit amet"],
values: ["Donec augue eros, ultrices."],
});
log.warn("Warning");
log.error(new Error("Unexpected error"));
```## Usage JavaScript
```js
const { createLogger, format, transports } = require("winston");
const winstonDevConsole = require("@epegzz/winston-dev-console").default;
const util = require("util");let log = createLogger({
level: "silly", // or use process.env.LOG_LEVEL
});// Note: You probably only want to use winstonDevConsole during development
log = winstonDevConsole.init(log);
log.add(
winstonDevConsole.transport({
showTimestamps: false,
addLineSeparation: true,
})
);log.silly("Logging initialized");
log.debug("Debug an object", { make: "Ford", model: "Mustang", year: 1969 });
log.verbose("Returned value", { value: util.format });
log.info("Information", {
options: ["Lorem ipsum", "dolor sit amet"],
values: ["Donec augue eros, ultrices."],
});
log.warn("Warning");
log.error(new Error("Unexpected error"));
```## API
## winstonDevConsole.format(options)
### options
Configuration object.
Type: `DevConsoleFormatOptions`### options.inspectOptions
`util.inspect()` [configuration object](https://nodejs.org/api/util.html#util_util_inspect_object_options).
Type: `Object`
### options.basePath
Used to remove the base path of the project when showing the file path of the log statement.
By default anything in the path before (and including) the `src` folder will be removed.
Type: `String`### options.addLineSeparation
Wheather or not to separate each log statement with a blank line.
Type: `Boolean`
Default: `true`### options.showTimestamps
Wheather or not to show timestamps
During development the timestamps are usually more noise then helpful, therefore disabled by default.
Type: `Boolean`
Default: `false`## Acknowledgements
This project is inspired by and partly shamelessly copied from [winston-console-format](https://github.com/duccio/winston-console-format)