Saltstack 简明教程
SaltStack - Logging
日志记录用于跟踪正在运行的软件事件。一个事件由一个描述性消息描述,该消息可选地包含变量数据。Salt 日志记录方法用于获取可能遇到的任何问题。您可以使用特定日志级别进行检查。
Logging is used to track the running software events. An event is described by a descriptive message, which can optionally contain variable data. Salt logging approach is used to get any issues, you may face. You can check out with specific log levels.
Configuration Settings
让我们详细了解日志记录的不同配置设置。
Let us understand the different configuration settings for logging, in detail.
LOG_FILE
Salt 日志记录通过文件传递,该文件包含用于标识的本地路径名称或网络位置。此文件被视为日志文件。
Salt log records are passed through the file, which contains the local path name or the network location for identification. This file is considered as the log file.
log_file: /var/log/salt/master
此处,文件取决于在 master 中执行的二进制文件。同样,您也可以在 minion 中执行,如下所示。
Here, the file dependent of the binary being executed in master. Similarly, you can execute in the minion as well, which is shown below.
log_file: /var/log/salt/minion
您还可以使用远程地址。使用远程地址的语法为 − <file|udp|tcp>://<host|socketpath>:<port-if-required>/<log-facility>。
You can also use remote address. The syntax for using the remote address is − <file|udp|tcp>://<host|socketpath>:<port-if-required>/<log-facility>.
log_file: udp://loghost:port
此处,日志设施默认为 LOG_USER。
Here, the Log-facility defaults to LOG_USER.
LOG_LEVEL
日志级别按数值分配的值排序。Python 库已默认定义了大多数日志级别。除此之外,Salt 还使用更多级别。下面介绍了其中一些级别。
The log levels are ordered in a numerically assigned value. Python library has defined most of the logging levels by default. In addition to that, Salt uses some more levels. Some of the levels are explained below.
-
log_level: error; level value is 40 − It indicates log statement record at error.
-
log_level: quiet; level value is 1000 − It indicates that nothing should be logged at this level.
-
log_level: info; level value is 20 − It indicates the normal log information.
-
log_level: warn; level value is 30 − It indicates log statement record at warning.
-
log_level: debug; level value is 10 − Information useful for debugging both salt implementations and salt code.
-
log_level: trace; level value is 5 − More detailed code-debugging information.
LOG_LEVEL_LOGFILE
它定义要发送到日志文件的消息级别。
It defines the level of messages to send to the log file.
log_level_logfile: info
LOG_DATEFMT
它定义日志日期格式。默认情况下,它表示为 %Y-%m-%d %H:%M:%S。
It defines the log date format. By default, it is represented as %Y-%m-%d %H:%M:%S.
log_datefmt_logfile: '%Y-%m-%d %H:%M:%S'
LOG_FMT_CONSOLE
它定义将消息记录到控制台日志的格式。Salt 使用自定义 LogRecord 属性为控制台日志输出着色。它遵循以下语法 −
It defines the format of the console logging the messages. Salt uses a custom LogRecord attributes to colorize the console log output. It follows the following syntax −
'%(colorlevel)s' # log level name colorized by level
'%(colorname)s' # colorized module name
'%(colorprocess)s' # colorized process number
'%(colormsg)s' # colorized messages name
LOG_FMT_LOGFILE
它定义将消息记录到日志文件的格式。基本语法如下 −
It defines the format of the log file logging the messages. The basic syntax is as follows −
%(asctime)s,%(msecs)03d [%(name)-17s][%(levelname)-8s] %(message)s
LOG_GRANULAR_LEVELS
该级别用于更具体地控制日志级别。
This level is used to control logging levels more specifically.
log_granular_levels:
'salt': 'info'
'salt.modules': ‘trace'
在这里,在“信息”级别的主 Salt 库将 salt.modules 设置为在跟踪级别记录日志。
Here, the Main salt library at the ‘info’ level sets the salt.modules to log at the trace level.
External Logging Handler
Salt 使用 LogStash 和 Sentry 外部日志处理程序进行日志记录。让我们在本章节详细了解它。
Salt uses LogStash and Sentry external log handler for logging. Let us understand about it in detail in this chapter.
LOGSTASH Handler
LogStash 是一个开源的服务器端安全数据处理管道。让我们考虑 Salt 中使用 LogStash 的一个简单 UDP 日志处理程序。
LogStash is an open source; server-side secure data processing pipeline. Let us consider a simple UDP logging handler in Salt that uses LogStash.
在 Salt 主文件中指定以下更改 −
Specify the following changes in the Salt master file −
logstash_udp_handler:
host: 127.0.0.1
port: 9999
version: 1
msg_type: logstash
然后在 Logstash 配置文件中添加更改 −
Then add the changes in the Logstash configuration file −
input {
udp {
port ⇒ 9999
codec ⇒ json
}
}
此处 UDP – 是输入,需要具有 json_event 的格式,而这正是我们通过网络发送的内容。
Here, UDP – is the input that needs to have a format as json_event, which is what we send over the wire.
SENTRY Logging Handler
Sentry 是生产部署中的实时错误跟踪以及用于重现和修复崩溃的信息。主文件中的默认配置在下面定义。
Sentry is real-time error tracking in production deployments and information to reproduce and fix crashes. The default configuration in the master file is defined below.
sentry_handler:
dsn: https://pub-key:secret-key@app.getsentry.com/app-id
log_level: debug
此处,sentry 处理程序的默认日志记录级别为 ERROR,但我们在 sentry_handler 配置密钥下定义了 debug log_level 。
Here, the default logging level for the sentry handler is ERROR, but we defined the debug log_level under the sentry_handler configuration key.