# @hatsy/log-z-request

> Hatsy request logger

Latest version **4.0.0** (published 2023-09-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hatsy/log-z-request
pnpm add @hatsy/log-z-request
yarn add @hatsy/log-z-request
bun add @hatsy/log-z-request
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2023-09-17 |
| First published | 2020-11-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ruslan Lopatin |
| Maintainers | lorus |
| Keywords | http-middleware, request-logging |

## Links

- npm: https://www.npmjs.com/package/@hatsy/log-z-request
- Repository: https://github.com/hatsyjs/log-z-request
- Issues: https://github.com/hatsyjs/log-z-request/issues
- npm.io page: https://npm.io/package/@hatsy/log-z-request

## Dependencies (2)

- [@proc7ts/logger](https://npm.io/package/@proc7ts/logger.md) ^2.0.0
- [@proc7ts/primitives](https://npm.io/package/@proc7ts/primitives.md) ^4.0.1

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2023-09-17
- 3.0.1 — 2023-01-27
- 3.0.0 — 2021-06-16
- 2.2.0 — 2021-05-28
- 2.1.0 — 2021-03-11
- 2.0.3 — 2020-11-27
- 2.0.2 — 2020-11-26
- 2.0.1 — 2020-11-10
- 2.0.0 — 2020-11-08

## README

# Log That Request

[![NPM][npm-image]][npm-url]
[![Build Status][build-status-img]][build-status-link]
[![Code Quality][quality-img]][quality-link]
[![Coverage][coverage-img]][coverage-link]
[![GitHub Project][github-image]][github-url]
[![API Documentation][api-docs-image]][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:

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

[npm-image]: https://img.shields.io/npm/v/@hatsy/log-z-request.svg?logo=npm
[npm-url]: https://www.npmjs.com/package/@hatsy/log-z-request
[build-status-img]: https://github.com/hatsyjs/log-z-request/workflows/Build/badge.svg
[build-status-link]: https://github.com/hatsyjs/log-z-request/actions?query=workflow:Build
[quality-img]: https://app.codacy.com/project/badge/Grade/92ac3a82e01347aaa57cb858a3e0811c
[quality-link]: https://www.codacy.com/gh/hatsyjs/log-z-request/dashboard?utm_source=github.com&utm_medium=referral&utm_content=hatsyjs/log-z-request&utm_campaign=Badge_Grade
[coverage-img]: https://app.codacy.com/project/badge/Coverage/92ac3a82e01347aaa57cb858a3e0811c
[coverage-link]: https://www.codacy.com/gh/hatsyjs/log-z-request/dashboard?utm_source=github.com&utm_medium=referral&utm_content=hatsyjs/log-z-request&utm_campaign=Badge_Coverage
[github-image]: https://img.shields.io/static/v1?logo=github&label=GitHub&message=project&color=informational
[github-url]: https://github.com/hatsyjs/log-z-request
[api-docs-image]: https://img.shields.io/static/v1?logo=typescript&label=API&message=docs&color=informational
[api documentation]: https://hatsyjs.github.io/log-z-request
[@run-z/log-z]: https://www.npmjs.com/package/@run-z/log-z

## Example Setup

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

---
_Source: https://npm.io/package/@hatsy/log-z-request · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
