GithubHelp home page GithubHelp logo

log-z-request's Introduction

Log That Request

NPM Build Status Code Quality Coverage GitHub Project API Documentation

Request logging by @run-z/log-z logger.

Contains a ZLogging capability that provides a request logger means containing ZLogger instance for handlers.

The log messages are actually written to the log under certain conditions. E.g. when request processing error occurred, error logged, or immediate logging triggered explicitly. Once immediate logging triggered, all log messages for the log are recorded to the log, as well as all messages logged after that.

To trigger immediate logging add immediate property with truthy value to log message details like this:

context.log.info('Immediate message', zlogDetails({ immediate: true }));

Example Setup

import { httpListener } from '@hatsy/hatsy';
import { ZLogging } from '@hatsy/log-z-request';
import { Rendering } from '@hatsy/router';
import { logZAtopOf, logZTimestamp, logZWithDetails, zlogDetails } from '@run-z/log-z';
import { logZToStream } from '@run-z/log-z/node';
import { createServer } from 'http';

const server = createServer(
  httpListener(
    {
      handleBy(handler) {
        // Set up logging before request processing.
        return ZLogging.with({
          by: logZTimestamp(
            // Log timestamp.
            logZToStream(process.stdout), // Log to standard output.
          ),

          forRequest(logger, { request: { method, url } }) {
            return logZWithDetails(
              {
                method, // Add request method to log message details.
                url, // Add request URL to log message details.
              },
              logZAtopOf(logger), // Create child logger per request.
            );
          },
        }).for(handler);
      },
    },
    Rendering.for(({ log, renderJson }) => {
      // Log immeditely instead of when error occurrred.
      log.info('Hello!', zlogDetails({ immediate: true }));
      renderJson({ hello: 'World!' });
    }),
  ),
);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.