Skip to content

macchiatojs/logger

Repository files navigation

@macchiatojs/logger

Macchiato.js logger based on pino.

Installation

# npm
$ npm install @macchiatojs/logger
# yarn
$ yarn add @macchiatojs/logger

Usage

This is a practical example of how to use.

with Macchiato.js - Express style;

import Macchiato, { Request, Response } from "@macchiatojs/kernel";
import logger from "@macchiatojs/logger";

const app = new Macchiato();

app
  .use(logger());
  .use((request: Request, response: Response) => {
    response.body = "Hello World";
  });

app.start(2222);

with Macchiato.js - Koa style;

import Macchiato, { Context } from "@macchiatojs/kernel";
import logger from "@macchiatojs/logger";

const app = new Macchiato();

app
  .use(logger());
  .use((context: Context) => {
    context.response.body = "Hello World";
  });

app.start(2222);

with raw Node.js

import http, { IncomingMessage, ServerResponse } from "http";
import { rawLogger } from "@macchiatojs/logger";

const server = http.createServer((request, response) => {
  logger()(req, res);
  response.statusCode = 200;
  response.write("Hello World !");
  response.end();
});

server.start(2222);

Note:
> rawLogger is re-export for pino-http and You can learn more about pino-http from the official documentation here.

License


MIT © Imed Jaberi

About

Macchiato.js logger based on pino.

Resources

License

Stars

Watchers

Forks

Packages

No packages published