4.0.0 • Published 8 months ago

@hatsy/log-z-request v4.0.0

Weekly downloads
11
License
MIT
Repository
github
Last release
8 months ago

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!' });
    }),
  ),
);
4.0.0

8 months ago

3.0.1

1 year ago

3.0.0

3 years ago

3.0.0-dev.0

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

4 years ago

2.0.0

4 years ago