1 Star 0 Fork 0

Take To / auto-logging

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
ISC

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

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:

    # 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:

    const logger = require('auto-logging').getLogger('name');
  4. Use the logger to print logs in your code.

    Example usage:

    // 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

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
ISC License Copyright (c) 2023, Take To Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

简介

Logging becomes effortless and efficient. 展开 收起
ISC
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
NodeJS
1
https://gitee.com/take-to/auto-logging.git
git@gitee.com:take-to/auto-logging.git
take-to
auto-logging
auto-logging
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891