Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1491 custom log levels can be silent #2366

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- 18
- 20
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,21 @@ To colorize the standard logging level add
```js
winston.format.combine(
winston.format.colorize(),
winston.format.json()
winston.format.simple()
);
```
where `winston.format.simple()` is whatever other formatter you want to use. The `colorize` formatter must come before any formatters adding text you wish to color.

### Colorizing full log line when json formatting logs

To colorize the full log line with the json formatter you can apply the following

```js
winston.format.combine(
winston.format.json(),
winston.format.colorize({ all })
);
```
where `winston.format.json()` is whatever other formatter you want to use. The `colorize` formatter must come before any formatters adding text you wish to color.

## Transports

Expand Down
7 changes: 0 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ declare namespace winston {
input: LeveledLogMethod;
silly: LeveledLogMethod;

// for syslog levels only
emerg: LeveledLogMethod;
alert: LeveledLogMethod;
crit: LeveledLogMethod;
warning: LeveledLogMethod;
notice: LeveledLogMethod;

query(
options?: QueryOptions,
callback?: (err: Error, results: any) => void
Expand Down
11 changes: 11 additions & 0 deletions lib/winston/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ class Logger extends Transform {
);
}

if (!Object.keys(this.levels).includes(this.level)){
const message = [
'[winston] Log level <${this.level}> is not defined in levels definition.',
'Please double check the setup of your transports and/or custom log levels.',
'This transport will be set to silent.',
'See https://github.com/winstonjs/winston#logging-levels for more information.'
]
console.warn(message.join('\n'));
this.silent = true;
}

if (exceptionHandlers) {
this.exceptions.handle(exceptionHandlers);
}
Expand Down
Loading