@@ -519,7 +519,7 @@ $ LOG_JSON_PRETTY=1 node example.js
519
519
Hive Logger includes some writers for common loggers of the JavaScript ecosystem with optional peer
520
520
dependencies.
521
521
522
- # ### `PinoLogWriter`
522
+ # ### `PinoLogWriter` (Node.js Only)
523
523
524
524
Use the [Node.js ` pino` logger library](https://github.com/pinojs/pino) for writing Hive Logger' s
525
525
logs.
@@ -553,7 +553,7 @@ log.info({ some: 'attributes' }, 'hello world')
553
553
```
554
554
{/* prettier-ignore-end */}
555
555
556
- #### `WinstonLogWriter`
556
+ #### `WinstonLogWriter` (Node.js Only)
557
557
558
558
Use the [Node.js `winston` logger library](https://github.com/winstonjs/winston) for writing Hive
559
559
Logger' s logs.
@@ -600,6 +600,8 @@ Writers can be synchronous (returning `void`) or asynchronous (returning a `Prom
600
600
writer performs asynchronous operations (like network requests or file writes), simply return a
601
601
promise from the ` write` method.
602
602
603
+ # ### Example of HTTP Writer
604
+
603
605
` ` ` ts
604
606
import { Attributes, ConsoleLogWriter, Logger, LogLevel, LogWriter } from ' @graphql-hive/logger'
605
607
@@ -623,6 +625,29 @@ log.info('Hello World!')
623
625
await log.flush () // make sure all async writes settle
624
626
` ` `
625
627
628
+ # ### Example of Daily File Log Writer (Node.js Only)
629
+
630
+ Here is an example of a custom log writer that writes logs to a daily log file. It will write to a
631
+ file for each day in a given directory.
632
+
633
+ ` ` ` ts filename=" daily-file-log-writer.ts"
634
+ import fs from ' node:fs/promises'
635
+ import path from ' node:path'
636
+ import { Attributes, jsonStringify, LogLevel, LogWriter } from ' @graphql-hive/logger'
637
+
638
+ export class DailyFileLogWriter implements LogWriter {
639
+ constructor(
640
+ private dir: string,
641
+ private name: string
642
+ ) {}
643
+ write(level: LogLevel, attrs: Attributes | null | undefined, msg: string | null | undefined) {
644
+ const date = new Date().toISOString ().split(' T' )[0]
645
+ const logfile = path.resolve(this.dir, ` ${this.name} _${date} .log` )
646
+ return fs.appendFile(logfile, jsonStringify({ level, msg, attrs }))
647
+ }
648
+ }
649
+ ` ` `
650
+
626
651
# ### Flushing and Non-Blocking Logging
627
652
628
653
The logger does not block when you log asynchronously. Instead, it tracks all pending async writes
0 commit comments