3.0.0 • Published 6 years ago

relic_logs v3.0.0

Weekly downloads
-
License
-
Repository
github
Last release
6 years ago

Request Life Cycle Logs aka "Relic Logs"

Example

This lib bundle and display all together logs from a HTTP request, including those from async events triggered by it. It was envisioned to be used with express js.

This is the 3.0.0 version, whreas the old eXperimental implementation, is now the standard.

Usage

1. Install & import

npm install relic_logs

const RelicLogs = require('relic_logs');

2. Init

app.use( RelicLogs.init( options ) );

Init before any express route declaration!

3. Setup routes

Set all routes you want to have a life cycle logging using the intercept middleware.

router.get('/foo', RelicLogs.intercept( 'subheading' ), function (req, res) {
  // some code
});

The intercept() method accepts one optional parameters, a subheading to be displayed after the log title.

4. Appending logs

Just use Relic.append inside the express route handler or function, promise or timeout that is called furthermore.

const Relic = require('relic_logs').loadExperimental();

router.get('/foo', RelicLogs.layup( ), function (req, res) {
  Relic.append( 'Starting the code with some params', req.query );
  // processing
  Relic.append( 'Responding to user', code, message );
});

The first parameter in the append will be the main message of the event, the others are sub messages, displayed as a second level.

5. Intercept uncaughtExceptions

app.use( RelicLogs.interceptError( ) );

Make sure to put this after all routes and middlewares to intercept any uncaught error. Express stuff, check it here.


Configurating

The are some customizations that can be made to shape the logger to better suite your needs.

All those are set using the .init method.

PropDescriptionDefault Value
envsArray of environments where the lib will produce output["staging", "production"]
titleThe title to any bundle of logsRequest Life Cycle
outputsArray of outputs configs. This is used tell Relic where to send the logs it generates, like console for example.see below

Output configuration

This is a single output. Your app can set any number of those.

PropDescriptionDefault Value
typeWhat type of logs this output will receive. any sends all types, logs sends just logs by the user "append" and uncaughtException send just unexpected errors caught by Relicany'
serializerHow this output will format its messages. console send those as colored terminal strings (like the print here), string sends plain string (with \r \n) and json send as a object'console'
senderA function used to expose the logs. Can be console.log if you want to just stdout or stderr, but can be a custom function that delivery the logs to somewhere else.console.log

Console output example:

  [
    {
      type: 'any',
      serializer: 'console'
    }
  ]

This will produce this:

JSON

JSON output example

  [
    {
      type: 'any',
      serializer: 'json'
    }
  ]

This will produce this:

JSON

Enjoy!!!

╔══════╗ ╔══════╗ ╔═╗      ╔══════╗ ╔══════╗
║ ╔══╗ ║ ║ ╔════╝ ║ ║      ╚═╗ ╔══╝ ║ ╔══╗ ║
║ ║  ║ ║ ║ ║      ║ ║        ║ ║    ║ ║  ╚═╝
║ ╚══╝ ║ ║ ╚══╗   ║ ║        ║ ║    ║ ║      ╭╮   ╭⎻⎻⎻╮╭⎻⎻⎻╮╭⎻⎻⎻╮
║ ╔╗ ╔═╝ ║ ╔══╝   ║ ║        ║ ║    ║ ║      ││   ││⎺││││⎺⎺ ││⎺⎺
║ ║╚╗╚╗  ║ ║      ║ ║        ║ ║    ║ ║  ╔═╗ ││   ││ ││││⎻⎻╮│╰⎻⎻╮
║ ║ ╚╗╚╗ ║ ╚════╗ ║ ╚════╗ ╔═╝ ╚══╗ ║ ╚══╝ ║ ││__ ││_││││̅_││ ̅_̅_││
╚═╝  ╚═╝ ╚══════╝ ╚══════╝ ╚══════╝ ╚══════╝ ╰───╯╰───╯╰───╯╰───╯

 ▓▓▓▓▓▓▓▓▓▓▓▓▓◤░░░░░░◥▓▓▓▓▓▓▓▓▓▓▓▓▓
 ▓▓▓▓▓▓▓▓▓◤░░░░░░░░░░░░░░◥▓▓▓▓▓▓▓▓▓
 ▓▓▓▓▓◤░░░░░░░░´    `░░░░░░░░◥▓▓▓▓▓
 ▓▓◤░░░░░░░░░´_⎯⎯⎯__* `░░░░░░░░░◥▓▓
 ▓▓◣░░░░░░░░░ˎ̽́★͘★ ★ ͙‾‾ˏ░░░░░░░░░◢▓▓
 ▓▓▓▓▓◣░░░░░░░░ˎ★͘ ͙★͘ˏ░░░░░░░░◢▓▓▓▓
 ▓▓▓▓▓▓▓▓▓◣░░░░░░░░░░░░░░◢▓▓▓▓▓▓▓▓▓
 ▓▓▓▓▓▓▓▓▓▓▓▓▓◣░░░░░░◢▓▓▓▓▓▓▓▓▓▓▓▓▓
3.0.0

6 years ago

2.4.0

7 years ago

2.3.4

7 years ago

2.3.3

7 years ago

2.3.2

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago