Skip to content

Commit

Permalink
feat(docs): Update format documentation, fixes #431
Browse files Browse the repository at this point in the history
  • Loading branch information
megahertz committed Jul 25, 2024
1 parent 5ecef34 commit e4dd9bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
26 changes: 22 additions & 4 deletions docs/transports/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,28 @@ log.transports.console.format = '[{h}:{i}:{s}.{ms}] [{label}] {text}';

## Function

`(message: LogMessage) => string`
`(params: FormatParams) => any[]`

```ts
interface FormatParams {
data: any[];
level: LogLevel;
logger: Logger;
message: LogMessage;
transport: Transport;
}
```

```js
log.transports.console.format = ({ message }) => {
return util.format(...message.data);
}
import util from 'node:util';

log.transports.console.format = ({ data, level, message }) => {
const text = util.format(...data);

return [
message.date.toISOString().slice(11, -1),
`[${level}]`,
text
];
};
```
10 changes: 9 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ declare namespace Logger {
'silly';
type LevelOption = LogLevel | false;

type Format = (({ message: LogMessage }) => any[]) | string;
interface FormatParams {
data: any[];
level: LogLevel;
logger: Logger;
message: LogMessage;
transport: Transport;
}

type Format = string | ((params: FormatParams) => any[]);

type FOpenFlags = 'r' | 'r+' | 'rs+' | 'w' | 'wx' | 'w+' | 'wx+' |
'a' | 'ax' | 'a+' | 'ax+';
Expand Down

0 comments on commit e4dd9bf

Please sign in to comment.