Logestic
An advanced and customisable logging library for ElysiaJS
Table of Contents
Installation
Add the package with your favourite package manager to your Elysia Project.
npm install --save logestic
yarn add logestic
pnpm add logestic
bun add logestic
Note: You must have elysia@1.0
installed in your project.
Usage
There are two ways to add logging to your Elysia application.
Preset request logging
Currently there are these presets availble to use.
import { Elysia } from 'elysia';
import { Logestic } from 'logestic';
const app = new Elysia()
.use(Logestic.preset('common'))
.get('/', () => "Hello from server")
.listen(5566);
Custom request logging
If you don't like any of presets, you can configure Logestic to log your requests in your way.
- Create a
Logestic
instance, optionally where you wish to log. - Call
use
to tell Logestic
the information you wish to use. - Finally, create an
Elysia
instance on custom
with the formating function.
import { Logestic } from 'logestic';
const fileLogger = (msg: string) => {
const logFile = Bun.file('requests.log');
const writer = logFile.writer();
writer.write(msg);
writer.flush();
}
export new Logestic(fileLogger)
.use(['method', 'path', 'time', 'status'])
.custom(({ method, path, time, status }) => {
return `[${time}]: ${method} ${path} | ${status}`
})
import myLogger from './logger'
const app = new Elysia()
.use(myLogger)
.get('/', () => "Hello from server")
.listen(5566);
Consider contibuting your own preset; check contributing guidelines.
Contributing Guidelines
See CONTRIBUTING.md
License
MIT
Authors