hapi-madero
A HapiJS plugin for writing logs to files
HapiJS plugin for writing logs to files. It creates 5 different files, depending on the log type ('info', 'error', 'warning', 'request', 'plugin'). I find it useful for services like splunk which can read logs from the server directly.
Installing
npm install hapi-madero
Usage
Here is a snippet of a basic setup:
// Deps =========================================const Hapi = ;const Madero = ; // Server =======================================const server = debug: false ; // Server Connection ============================server; // Madero Options ===============================const maderoOptions = path: './logs' ; // Adding Madero Plugin =========================server;
Plugin Options
path
- String
Madero needs to know where to save the files, this will tell madero where the log files will be saved. I.E.: ./logs
will create a directory in the project root called 'logs'. Defaults to path.resolve(path.dirname(require.main.filename), './logs')
(which will create the directory where the main file is run)
stopTimeoutMsec
- Number
Overrides the timeout in millisecond before forcefully terminating a connection. Defaults to 15000
(15 seconds)
silent
- Boolean
If you do not want to see every log in the console. Defaults to false
signals
- Boolean
Whether you want madero to handle SIGTERM
or SIGINT
. Defaults to true
exceptions
- Boolean
Whether you want madero to handle uncaughtException
or unhandledRejection
. Defaults to true
timestampKey
- String
In case you need to specify the timestamp key for the events, you can change it here. Defaults to @timestamp
unixStamp
- Boolean
By default, each event timestamp is set to a ISO string: YYYY-MM-DDTHH:mm:ss.sssZ
, changing this to true
will change to a unix stamp of 13 numbers.
Plugin Methods
write
(options, [callback])
options
- required - Object
Recieves a the following:
async
- Boolean - Wether to write to file async or notrequest
- Object - The request objectentry
- Object - The entry that will be written to file. This expects the following:message
- required - String - Entry messagetags
- required - Array - Array of strings used to identify the event. Tags are used instead of log levels and provide a much more expressive mechanism for describing and filtering events.error
- Object - An error objectdata
- Object - Any additional data to be saved with the entry
callback
- function
Called once it has finshed writing to file
console
(data, [type, [callback]])
data
- Object
This will be the object that you want to log to console
type
- String
Can be one of: error
, info
, warn
. Defaults to info
callback
- function
Called once it has finshed logging to console
License
This project is licensed under the MIT License - see the LICENSE.md file for details