代码拉取完成,页面将自动刷新
Logging becomes effortless and efficient.
npm install auto-logging --save
Create a new configuration file logging.yml
or logging.yaml
in the project's root directory.
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
Import the LoggingFactory
package in your project.
Example in Node.js:
const logger = require('auto-logging').getLogger('name');
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.");
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。