# auto-logging

> Logging becomes effortless and efficient.

Latest version **1.2.0** (published 2024-01-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install auto-logging
pnpm add auto-logging
yarn add auto-logging
bun add auto-logging
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2024-01-14 |
| First published | 2023-12-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14.19.0 |
| Dependencies | 9 |
| Unpacked size | 34.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | take to |
| Maintainers | take_to |
| Keywords | auto, logging |

## Links

- npm: https://www.npmjs.com/package/auto-logging
- Repository: https://gitee.com/take-to/auto-logging
- npm.io page: https://npm.io/package/auto-logging

## Dependencies (9)

- [nconf](https://npm.io/package/nconf.md) ^0.12.1
- [colors](https://npm.io/package/colors.md) ^1.4.0
- [logform](https://npm.io/package/logform.md) ^2.6.0
- [winston](https://npm.io/package/winston.md) ^3.11.0
- [nconf-yaml](https://npm.io/package/nconf-yaml.md) ^1.0.2
- [cosmiconfig](https://npm.io/package/cosmiconfig.md) ^8.3.6
- [triple-beam](https://npm.io/package/triple-beam.md) ^1.4.1
- [color-scheme](https://npm.io/package/color-scheme.md) ^1.0.1
- [winston-daily-rotate-file](https://npm.io/package/winston-daily-rotate-file.md) ^4.7.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

- 1.2.0 (latest) — 2024-01-14
- 1.1.0 — 2024-01-12
- 1.0.0 — 2023-12-28

## README

# Auto-Logging

Logging becomes effortless and efficient.

## Features

- [✓] Logging levels
- [✓] Logging to console
- [✓] Logging to file
- [✓] Logging to custom output
- [✓] Logging formatting
- [✓] Logging rotation
- [✓] Logging filtering

## Installation

```bash
npm install auto-logging --save
```

## Usage

1. Create a new configuration file `logging.yml` or `logging.yaml` in the project's root directory.

2. Fill in the configuration file with your custom settings.

    Example `logging.yml`:

    ```yaml
    # Logging Configuration
    logging:
      template: "%timestamp%%level%%label%%module%%message%%metadata%"
      formats:
        timestamp: "YYYY.MM.DD-HH:mm:ss.SSS ZZ"
        label: auto-logging
        json: false
        pad: true
        align: false
        attributeformat:
          level: " %attribute%"
          label: " [%attribute%]"
          module: " [%attribute%] "
          metadata: " (%attribute%)"
        colorize:
          all: true
          colors:
            info: green
            error: red
            warn: yellow
            debug: grey
      targets:
        console:
          target: console
          enabled: true
          options:
            level: info
        file:
          target: file
          enabled: true
          options:
            level: warn
            filename: "logging.log"
        rotatingInfo:
          target: daily-rotate-file
          enabled: true
          options:
            level: info
            datePattern: "YYYY-MM-DD"
            zippedArchive: true
            filename: "logs/%DATE%/info.log"
            options:
              flags: a
              mode: 0666
        rotatingDebug:
          target: daily-rotate-file
          enabled: true
          options:
            level: debug
            datePattern: "YYYY-MM-DD"
            zippedArchive: true
            filename: "logs/%DATE%/debug.log"
            options:
              flags: a
              mode: 0666
        rotatingWarn:
          target: daily-rotate-file
          enabled: true
          options:
            level: warn
            datePattern: "YYYY-MM-DD"
            zippedArchive: true
            filename: "logs/%DATE%/warn.log"
            options:
              flags: a
              mode: 0666
        rotatingError:
          target: daily-rotate-file
          enabled: true
          options:
            level: error
            datePattern: "YYYY-MM-DD"
            zippedArchive: true
            filename: "logs/%DATE%/error.log"
            options:
              flags: a
              mode: 0666
    ```

3. Import the `LoggingFactory` package in your project.

    Example in Node.js:

    ```javascript
    const logger = require('auto-logging').getLogger('name');
    ```

4. Use the logger to print logs in your code.

    Example usage:

    ```javascript
    // Log an error message
    logger.error("This is an error message.");

    // Log a warning message
    logger.warn("This is a warning message.");

    // Log an informational message
    logger.info("This is an informational message.");

    // Log a debug message
    logger.debug("This is a debug message.");
    ```

## Default Logging Configuration

```yaml
logging:
  # Configurations related to the logging mechanism
  # Specifies the message structure through placeholders
  template: "%timestamp%%level%%label%%module%%message%%metadata%"
  # Enables the different formats to apply to the log messages FOR ALL transports
  # Each format can be disabled by setting it to false
  formats:
    # Adds a timestamp to the messages with the following format
    timestamp: "YYYY.MM.DD-HH:mm:ss.SSS"
    # Adds a specified label to every message. Useful for distributed workers scenario
    label: auto-logging
    # serializes the log messages as JSON
    json: false
    # pads the levels to be the same length
    pad: true
    # adds a tab delimiter before the message to align it in the same place
    align: true
    # specifies formatting strings for different log message attributes
    attributeformat:
      # add a space before the level
      level: " %attribute%"
      # put [] around the label and space before it
      label: " [%attribute%]"
      # put [] around the module name and space before/after it
      module: " [%attribute%] "
      # put () around the metadata and space before it
      metadata: " (%attribute%)"
    # defines coloring for the different levels for each (or all) message property
    colorize:
      # Apply it to levels
      level: true
      # Apply it to messages
      message: false
      # The colors for each level
      colors:
        info: green
        error: red
        warn: yellow
        debug: grey
  # Lists the targets (winston transports)
  targets:
    console:
      target: console # Defines a console target
      enabled: true # Enables the target
      options: # These are passed to the winston console target as-is
        level: info
    # Defines a file target with debug level but is disabled by default
    file:
      target: file
      enabled: false
      options:
        level: debug
        filename: logging.log
        maxSize: 5m
        zippedArchive: false
        options:
          flags: a
          mode: 0666
```

---
_Source: https://npm.io/package/auto-logging · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
