All Projects → pablosichert → Concurrency Logger

pablosichert / Concurrency Logger

Licence: mit
Log HTTP requests/responses separately, visualize their concurrency and report logs/errors in context of a request.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Concurrency 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 (-8.5%)
Mutual labels:  middleware, logging, logger
Nestjs Pino
Platform agnostic logger for NestJS based on Pino with REQUEST CONTEXT IN EVERY LOG
Stars: ✭ 283 (-29.25%)
Mutual labels:  logging, logger
Tty Logger
A readable, structured and beautiful logging for the terminal
Stars: ✭ 280 (-30%)
Mutual labels:  logging, logger
Tslog
📝 tslog - Expressive TypeScript Logger for Node.js.
Stars: ✭ 321 (-19.75%)
Mutual labels:  logging, logger
Monolog
Requirements
Stars: ✭ 19,361 (+4740.25%)
Mutual labels:  logger, logging
Pygogo
A Python logging library with superpowers
Stars: ✭ 265 (-33.75%)
Mutual labels:  logging, logger
Grant
OAuth Proxy
Stars: ✭ 3,509 (+777.25%)
Mutual labels:  middleware, koa
gxlog
A concise, functional, flexible and extensible logger for go.
Stars: ✭ 65 (-83.75%)
Mutual labels:  logger, logging
Electron Timber
Pretty logger for Electron apps
Stars: ✭ 337 (-15.75%)
Mutual labels:  logging, logger
Go Grpc Middleware
Golang gRPC Middlewares: interceptor chaining, auth, logging, retries and more.
Stars: ✭ 4,170 (+942.5%)
Mutual labels:  middleware, logging
Cocoadebug
iOS Debugging Tool 🚀
Stars: ✭ 3,769 (+842.25%)
Mutual labels:  logging, logger
Home
Project Glimpse: Node Edition - Spend less time debugging and more time developing.
Stars: ✭ 260 (-35%)
Mutual labels:  middleware, logging
stats
📊 Request statistics middleware that stores response times, status code counts, etc
Stars: ✭ 15 (-96.25%)
Mutual labels:  middleware, koa
Cors
🔮Supported(Laravel/Lumen/PSR-15/Swoft/Slim/ThinkPHP) - PHP CORS (Cross-origin resource sharing) middleware.
Stars: ✭ 266 (-33.5%)
Mutual labels:  middleware, request
koa-waterline
Deprecated: A middleware for your hose
Stars: ✭ 14 (-96.5%)
Mutual labels:  middleware, koa
Analog
PHP logging library that is highly extendable and simple to use.
Stars: ✭ 314 (-21.5%)
Mutual labels:  logging, logger
koa2-winston
koa2 version winston logger like express-winston
Stars: ✭ 37 (-90.75%)
Mutual labels:  koa, logger
doa
A middleware framework for Deno's http serve🦕. Transplanted from Koa with ❤️
Stars: ✭ 20 (-95%)
Mutual labels:  middleware, koa
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 (-17.5%)
Mutual labels:  logging, logger
Node Tutorial
☺️Some of the node tutorial -《Node学习笔记》
Stars: ✭ 364 (-9%)
Mutual labels:  koa, request

concurrency-logger

NPM version Build status Coverage status Dependency status Dev dependency status

HTTP logging middleware especially useful to unwind concurrent operations without losing the request context

HTTP logs in a terminal, visualizing server status codes, response times, debug information and errors for concurrent requests
Launch demo in your browser

Install

$ npm install concurrency-logger

Usage

With koa

Basic usage

import Koa from 'koa';
import createLogger from 'concurrency-logger';

const app = new Koa;

// Logger is stateful as it contains information about concurrent requests
// Same instance needs to be reused across requests
const logger = createLogger(/* options */);

app.use(logger);

Log from middleware

// Log something in context to a specific request to trace it back easily -
// also when there are multiple concurrent requests
app.use(async (context, next) => {
    context.log('Log!');
    context.log.info('Info!');
    context.log.error('Error!');

    await next();
});

Attach more context to the log

const logger = createLogger({
    req: context => (
        context.originalUrl + '\n' +
        context.get('User-Agent')
    )
});

Include localized timestamps

const logger = createLogger({
    timestamp: true
});

Write log to file

import { createWriteStream } from 'fs';

// To read log use program that interprets ANSI escape codes,
// e.g. cat or less -r
const log = createWriteStream('logs/requests.log');

const logger = createLogger({
    reporter: log
});

Adjust alert levels per method and response time

const logger = createLogger({
    getLevel: (responseTime, context) => {
        /*
            GET
              0 -  99ms: 0
            100 - 149ms: 1
            150 - 199ms: 2
            200 - 249ms: 3
            250 - 299ms: 4
            300 - 349ms: 5
            > 350ms    : 6

            POST
              0 - 149ms: 0
            150 - 225ms: 1
                   ... : ...
        */

        let threshold = 50; // ms

        if (['POST', 'PUT'].includes(context.method)) {
            threshold *= 1.5;
        }

        return Math.floor(responseTime / threshold) - 1;
    }
});

Standalone

import createLogger from 'concurrency-logger';

const logger = createLogger(/* options */);

(async () => {
    const context = {
        method: 'GET',
        originalUrl: '/'
    };

    const next = async () => {
        await new Promise(resolve => setTimeout(resolve, 100));

        context.status = 200;
    };

    try {
        await logger(context, next);
    } catch (error) {
        // Errors are passed through
    }
})();

API

Option Type Default Description Example
minSlots integer 1 Amount of space that is provisioned to display concurrent request lanes. Number of lanes will automatically scale up as the number of concurrent requests grow. 3
getLevel integer: function(responseTime: integer) responseTime => Math.floor(responseTime / 50) - 1 Map response time to alert level. Alert levels go from 0 (default color) to 6 (dark red). By default that means <100ms: 0, <150ms: 1 <200ms: 2, ..., >=350ms: 6. responseTime => Math.floor(responseTime / 100)
width integer, boolean(false) undefined If no width is provided, it will be dynamically read from process.stdout.columns. Pass in an integer to break all lines according to the specified fixed (terminal character) width. Pass in false if you want the lines not to break at all. 80, 132, false
timestamp boolean false Print localized timestamp for every requests. true, false
slim boolean false "Slim mode": don't use an extra character between request lanes to shrink width, but make them harder to separate visually. true, false
reporter writable stream process.stdout Specify a stream that handles the output lines. Write to terminal or stream to a log file, for example. Note that the lines contain ANSI color codes, so when streaming to a file you might need a program that can read those. E.g. less -r requests.log require('fs').createWriteStream('logs/requests.log')
req any: function(context: object) context => context.originalUrl Attach additional information to the request log line. context => context.originalUrl + '\n' + context.get('User-Agent')
res any: function(context: object) context => context.originalUrl Attach additional information to the response log line. context => context.originalUrl + '\n' + context.get('User-Agent')

Developing

Install development dependencies

$ npm install

Create new fixtures to test against

$ npm run create-fixtures

Manually review fixtures (you need a program that renders ANSI escape codes)

$ less -r test/fixtures/*

Run tests

$ npm test

Run code linter

$ npm run lint

Compile to ES5 from /src to /lib

$ npm run compile

Initialize demo project

$ git clone [email protected]:PabloSichert/concurrency-logger demo
$ cd demo
demo $ git checkout gh-pages
demo $ npm install

Build demo

demo $ npm run compile
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].