Skip to content

Commit

Permalink
Add Bunyan lgging example
Browse files Browse the repository at this point in the history
  • Loading branch information
otherguy committed Nov 24, 2023
1 parent 7989ec3 commit 8780b6c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ Since the `console` is very limited, you may want to use a custom logger. The re

See the [examples](examples) directory for implementation examples.

* [Pino](https:/pinojs/pino) (see [Pino](examples/pino.ts) and [Pino Pretty](examples/pino-pretty.ts) examples)
* [Winston](https:/winstonjs/winston) (see [Winston](examples/winston.ts) example)
* [Pino](https:/pinojs/pino) (see [example](examples/pino.ts))
* [Winston](https:/winstonjs/winston) (see [example](examples/winston.ts))
* [Bunyan](https:/trentm/node-bunyan) (see [example](examples/bunyan.ts))

## 🪜 Examples

Expand All @@ -100,7 +101,7 @@ A few examples are provided in the [`examples`](examples) directory.

* [ ] Add logger format classes
* [ ] Add whitelist for request parameters
* [ ] Add more logger examples (Bunyan, npmlog)
* [ ] Add more logger examples (~~Bunyan~~, npmlog)

## ⚖️ License

Expand Down
Binary file modified bun.lockb
Binary file not shown.
32 changes: 32 additions & 0 deletions examples/bunyan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Elysia } from "elysia";
import { ElysiaLogging } from "../src/elysiaLogging";
import { type Logger } from "../src/types";
import { createLogger, INFO } from 'bunyan'

// Define Bunyan logger
const logger : Logger = createLogger ({
name: "logger",
streams: [ { level: INFO, stream: process.stdout } ],
});

const elysiaLogging = ElysiaLogging(logger, {
// Access logs in JSON format
format: "json",
})

//
const app = new Elysia()
.use(elysiaLogging)
.get("/", () => {
if (Math.random() < 0.75) {
return new Response("Welcome to Bun!");
}
throw new Error("Whoops!");
})
.listen({
port: Bun.env.PORT ?? 3000,
maxRequestBodySize: Number.MAX_SAFE_INTEGER,
});

logger.info(`🦊 Running at http://${app.server?.hostname}:${app.server?.port}`);

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@
"pino-pretty": "^10.2.3"
},
"devDependencies": {
"@types/bunyan": "^1.8.11",
"@types/jest": "^29.5.10",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"bun-types": "^1.0.14",
"bunyan": "^1.8.15",
"eslint": "^8.54.0",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
Expand Down

0 comments on commit 8780b6c

Please sign in to comment.