All Projects → pagarme → Escriba

pagarme / Escriba

Licence: mit
📜 Logging on steroids

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Escriba

Quill
Asynchronous Low Latency C++ Logging Library
Stars: ✭ 422 (+1306.67%)
Mutual labels:  logging, logger
Logbook
An extensible Java library for HTTP request and response logging
Stars: ✭ 822 (+2640%)
Mutual labels:  logging, logger
Izumi
Productivity-oriented collection of lightweight fancy stuff for Scala toolchain
Stars: ✭ 423 (+1310%)
Mutual labels:  logging, logger
Monolog
Requirements
Stars: ✭ 19,361 (+64436.67%)
Mutual labels:  logger, logging
Thoth
An Error Logger for Go
Stars: ✭ 22 (-26.67%)
Mutual labels:  logging, logger
Onelog
Dead simple, super fast, zero allocation and modular logger for Golang
Stars: ✭ 389 (+1196.67%)
Mutual labels:  logging, logger
G3log
G3log is an asynchronous, "crash safe", logger that is easy to use with default logging sinks or you can add your own. G3log is made with plain C++14 (C++11 support up to release 1.3.2) with no external libraries (except gtest used for unit tests). G3log is made to be cross-platform, currently running on OSX, Windows and several Linux distros. See Readme below for details of usage.
Stars: ✭ 677 (+2156.67%)
Mutual labels:  logging, logger
Caterpillar
Caterpillar is the ultimate logging system for Deno, Node.js, and Web Browsers. Log levels are implemented to the RFC standard. Log entries can be filtered and piped to various streams, including coloured output to the terminal, the browser's console, and debug files. You can even write your own transforms.
Stars: ✭ 330 (+1000%)
Mutual labels:  logging, logger
Jslogger
Integrate JavaScript Logging with ASP.NET Core Logging APIs
Stars: ✭ 19 (-36.67%)
Mutual labels:  logging, logger
Simplog
A simple logger. No dependencies, no special features, just logging.
Stars: ✭ 17 (-43.33%)
Mutual labels:  logging, logger
Laravel Logger
An out the box activity logger for your Laravel or Lumen application. Laravel logger is an activity event logger for your laravel application. It comes out the box with ready to use with dashboard to view your activity. Laravel logger can be added as a middleware or called through a trait. This package is easily configurable and customizable. Supports Laravel 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6, and 7+
Stars: ✭ 366 (+1120%)
Mutual labels:  logging, logger
Cartus
A structured logging abstraction with multiple backends.
Stars: ✭ 21 (-30%)
Mutual labels:  logging, logger
Cocoadebug
iOS Debugging Tool 🚀
Stars: ✭ 3,769 (+12463.33%)
Mutual labels:  logging, logger
Concurrency Logger
Log HTTP requests/responses separately, visualize their concurrency and report logs/errors in context of a request.
Stars: ✭ 400 (+1233.33%)
Mutual labels:  logging, logger
Electron Timber
Pretty logger for Electron apps
Stars: ✭ 337 (+1023.33%)
Mutual labels:  logging, logger
Gf
GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
Stars: ✭ 6,501 (+21570%)
Mutual labels:  logging, logger
Analog
PHP logging library that is highly extendable and simple to use.
Stars: ✭ 314 (+946.67%)
Mutual labels:  logging, logger
Tslog
📝 tslog - Expressive TypeScript Logger for Node.js.
Stars: ✭ 321 (+970%)
Mutual labels:  logging, logger
Snoopy
Snoopy is a small library that logs all program executions on your Linux/BSD system (a.k.a. Snoopy Logger).
Stars: ✭ 835 (+2683.33%)
Mutual labels:  logging, logger
Znetcs.aspnetcore.logging.entityframeworkcore
This is Entity Framework Core logger and logger provider. A small package to allow store logs in any data store using Entity Framework Core.
Stars: ✭ 24 (-20%)
Mutual labels:  logging, logger

Coverage Status Build Status Escriba Logo

Logging on steroids

Escriba

The motivations for this library is to provide ways for a better express application logging. To achieve this goal we provide tools to managing logs, a log tracker across services and we add relevant information to your log.

Cool features

  • JSON format
  • Unique id
  • Request and responses share the same id. This enables tracking the path of a request across your services
  • Hide secret information based on regex
  • Adds extra information to your logs as pid, hostname, level, startTime, and latency
  • Filter props from request and/or response
  • Skip routes based on methods/rules/body props

Installation

npm install --save escriba

Usage

Escriba provides two kinds of logger: logger and httpLogger.

Logger

Use logger log across your application.

For example, to log some information from an userController hidding the password property:

const log4js = require('log4js').getLogger()
const escriba = require('escriba')
const cuid = require('cuid')

log4js.level = 'info'

const { logger } = escriba({
  loggerEngine: log4js,
  service: 'api',
  sensitive: {
    password: {
      paths: ['message.password'],
      pattern: /\w.*/g,
      replacer: '*'
    }
  }
})

logger.info({ text: 'Setting user permission', password: 'abc' }, { id: cuid(), from: 'userController' })

Http logger

Use httpLogger to log an http request and response.

For this example we'll long only some properties: id, body and statusCode.

We'll also skip status route, options method and body property from routes that end with .csv or .xlsx.

It's important to hide sentive information like api_key.

const express = require('express')
const log4js = require('log4js').getLogger()
const escriba = require('escriba')
const cuid = require('cuid')
const roomController = require('./controllers/room')

const app = express()

const { httpLogger } = escriba({
  loggerEngine: log4js,
  sensitive: {
    password: {
      paths: ['body.api_key'],
      pattern: /(ak_test|ak_live).*/g,
      replacer: '*'
    }
  },
  httpConf: {
    logIdPath: 'headers.my_path_id',
    propsToLog: {
      request: ['id', 'url', 'body'],
      response: ['id', 'url', 'body', 'statusCode', 'latency']
    },
    envToLog: ['SHELL', 'PATH'],
    skipRules: [
      {
        route: /\/status/,
        method: /.*/,
        onlyBody: false
      },
      {
        route: /.*\.(csv|xlsx)$/,
        method: /GET/,
        onlyBody: true
      },
      {
        route: /.*/,
        method: /OPTIONS/,
        onlyBody: false
      }
    ],
    propMaxLength: {
      body: 2048,
      url: 1024
    },
    propsToParse: {
      request: {
         'id': String,
         'body.document_number': Number,
      },
      response: {
         'body.customer.id': Number
      }
    }
  }
})

app.use(httpLogger)

app.get('/room/:id', roomController.index)
app.post('/room', roomController.save)

Every request and response will be logged, and the coolest part: both will have the same id. This is important because you can search for this id and get all information about your request and response.

As you can see we have the logIdPath inside the httpConf object. This property allow you to pick log id from a desired path in request object. If you don't pass this property escriba will generate a new id for your request/response logs using cuid.

This id is injected in the req object, so if you need to log some extra information between a request and response just do something like this:

logger.info('some controller information', { id: req.id })

Also it's possible to skip logs or only the body property through skipRules, in the example we are skiping logs from route /status for all methods and skiping the body property from routes that ends with .csv or .xlsx.

The propMaxLength attribute is responsible to limit the number of characters for certain properties if they exist within propsTolog definition.

The propsToParse attribute is responsible to parse any atribute based on a path, the parsing works by providing a valid javascript native Function (e.g String, Number etc).

Masks

Just like the loggerEngine option, escriba accepts two types of mask engines, they are iron-mask and mask-json. If you don't pass any maskEngine, iron-mask will be used as default.

iron-mask

const { logger, httpLogger } = escriba({
  loggerEngine,
  service: 'bla',
  // no `maskEngine` informed, `iron-mask` will be used
  sensitive: { // `iron-mask` sensitive format
    secret: {
      paths: ['message.secret', 'message.metadata.secret', 'body.secret'],
      pattern: /\w.*/g,
      replacer: '*',
    },
  },
})

mask-json

const maskJson = require('mask-json')
const { logger, httpLogger } = escriba({
  loggerEngine,
  service: 'bla',
  maskEngine: maskJson,
  sensitive: { // `mask-json` sensitive format
    blacklist: ['secret'],
    options: {
      replacement: '*',
    },
  },
})

Integrations

You can enable integrations by simply passing a integrations key in the config. Like this:

escriba({
  integrations: {
    datadog: true
  }
})

But remember, for each integration to work you may need to configure your application via environment variables.

Datadog

You'll need to install dd-trace in your application. The Datadog integration enable this feature: https://docs.datadoghq.com/tracing/advanced/connect_logs_and_traces/.

Examples

The log-generator inside examples folder will run a Node.js application that will make a request for itself every in an interval defined by the user (in milliseconds). The application will get input values from an environment variable ESCRIBA_TIMEOUT(3000 is the default value, this represents 3 seconds)

To use log-generator through Docker use these commands inside the log-generator folder:

docker build -t pagarme/log-generator:latest .

docker run -e ESCRIBA_TIMEOUT=3000 -p 3000:3000 -d -v $(cd ../../ && pwd):/log-generator/node_modules/escriba pagarme/log-generator:latest

And to make some manual requests use:

curl -H "Content-Type: application/json" -X GET http://localhost:3000/escriba

curl -H "Content-Type: application/json" -X POST -d '{"username":"a name"}' http://localhost:3000/escriba

The log-generator example will get Escriba library from npm. If you want to get the library directly from the repository run docker with -v:

docker run -e ESCRIBA_TIMEOUT=3000 -p 3000:3000 -d -v $(cd ../../ && pwd):/escriba pagarme/log-generator:latest

License

The MIT License (MIT)
Copyright (c) 2017 Pagar.me Pagamentos S/A
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].