@skrenek/adonisjs-request-logger
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

adonisjs-request-logger

A simple request logger module for AdonisJS.

npm-image license-image typescript-image

This module provides a request (access) logger for AdonisJS.

The supported format codes approximate what Apache log formats support, but not all formats are supported. I have never needed more than what is provided here. If you find you'd like some added, pull requests are very much welcomed. 😊

See the LogFormatProperties enum for the currently supported formats.

A helper is also provided for an approximation of Apache log format's "combined" log format via the LogFormat.combined enum member. This is the default format.

Finally, the log messages are created via AdonisJS's built in Logger class as info-level messages.


Installation

npm install @skrenek/adonisjs-request-logger

node ace configure @skrenek/adonisjs-request-logger

The configure command adds the provider to your application and generates the default config file.


Usage

Registering the Middleware

Register the middleware in start/kernel.ts by adding:

() => import('@ioc:Adonis/Addons/Skrenek/RequestLogger') to your global middleware array. See the example below.

Server.middleware.register([
  () => import('@ioc:Adonis/Core/BodyParser'),
  () => import('@ioc:Adonis/Addons/Skrenek/RequestLogger'), // <- add this line
])

Configuring the Log Format

The log format can be customized by configuring it in config/request-logger.ts. Only one property is exposed: format. Set it to a string containing log formats, or use the shortcut string "combined" to set it to the best approximation of Apache's combined log format.

Supported log formats can be found here.

One final note. If you're using AdonisJS's supported authentication module, the remote user log format (%u) will display the authenticated user's email address if available.

Package Sidebar

Install

npm i @skrenek/adonisjs-request-logger

Weekly Downloads

3

Version

0.1.2

License

MIT

Unpacked Size

17 kB

Total Files

14

Last publish

Collaborators

  • skrenek