SaltStack 日志管理

本模块的内容是根据官方v2018.3.0版本的英文资料翻译得到。

Salt项目试图让日志记录为您工作,并帮助我们解决可能遇到的任何问题。

如果你想获得更多的关于Salt的日志系统的基本信息,请转到logging development document。如果你想要的是配置Salt的日志系统,请继续阅读。

 

1、 日志级别

日志级别按数字顺序排列,以便将日志级别设置为特定级别时,将记录该级别及更高级别的所有日志语句。 例如,设置log_level:error会在error、critical、和quiet级别记录语句,当然在quiet级别是不会记录任何内容的。

大多数日志记录级别在Python日志记录库中默认定义,可以在官方Python文档中找到。 除了标准级别之外,Salt还使用更多级别。 下表列出了所有可用的Salt日志级别。

注:Salt使用的Python依赖关系可能会定义并使用其他日志记录级别。 例如,multiprocessing 标准Python库的Python 2版本使用subwarning,25 和subdebug,5.。

Level

Numeric value

Description

quiet

1000

Nothing should be logged at this level

critical

50

Critical errors

error

40

Errors

warning

30

Warnings

info

20

Normal log information

profile

15

Profiling information on salt performance

debug

10

Information useful for debugging both salt implementations and salt code

trace

5

More detailed code debugging information

garbage

1

Even more debugging information

all

0

Everything


2、可用的配置设置

log_file

日志记录可以发送到常规文件,本地路径名或网络位置。 远程日志记录配置为使用rsyslogd(8)(例如:file:///dev/log),rsyslogd(8)配置为网络日志记录时效果最佳。 远程地址的格式是:<file|udp|tcp>://<host|socketpath>:<port-if-required>/<log-facility>。 其中,日志设施是SyslogHandler文档中定义的系统日志设施的符号名称。 它默认为LOG_USER。

默认值:取决于正在执行的二进制文件,例如,salt-master是 /var/log/salt/master。

例如:

log_file: /var/log/salt/master
log_file: /var/log/salt/minion
log_file: file:///dev/log
log_file: file:///dev/log/LOG_DAEMON
log_file: udp://loghost:10514

log_level

DefaultWarning

要发送到控制台的日志记录消息的级别,取值范围是all, garbage, trace, debug, profile, info, warning, error, critical, quiet。

log_level: warning

注意:在salt配置文件中添加log_level:quiet以完全禁用日志记录。 如果是在命令行中运行salt,请改用--log-level = quiet。

log_level_logfile

Default: info

要发送到日志文件的消息级别。取值范围是all, garbage, trace, debug, profile, info, warning, error, critical, quiet.

log_level_logfile: warning

log_datefmt

Default: %H:%M:%S

控制台日志消息中使用的日期和时间格式。 可以在time.strftime上看到允许的日期/时间格式。

log_datefmt: '%H:%M:%S'

log_datefmt_logfile

Default: %Y-%m-%d %H:%M:%S

日志文件消息中使用的日期和时间格式。 可以在time.strftime上看到允许的日期/时间格式。

log_datefmt_logfile: '%Y-%m-%d %H:%M:%S'

log_fmt_console

Default: [%(levelname)-8s] %(message)s

控制台日志消息的格式。 所有标准的python logging LogRecord属性都可以使用。 Salt还提供了这些自定义LogRecord属性来着色控制台日志输出:

'%(colorlevel)s'   # log level name colorized by level
'%(colorname)s'    # colorized module name
'%(colorprocess)s' # colorized process number
'%(colormsg)s'     # log message colorized by level

注:%(colorlevel)s,%(colorname)s和%(colorprocess)LogRecord属性还包括填充和括号括起来,[and]以匹配其非彩色LogRecord属性的默认值。

log_fmt_console: '[%(levelname)-8s] %(message)s'

log_fmt_logfile

Default: %(asctime)s,%(msecs)03d [%(name)-17s][%(levelname)-8s] %(message)s

日志文件日志消息的格式。 所有标准的python logging LogRecord属性都可以使用。 Salt还提供了这些定制的LogRecord属性,其中包括填充和括号[and]:

'%(bracketlevel)s'   # equivalent to [%(levelname)-8s]
'%(bracketname)s'    # equivalent to [%(name)-17s]
'%(bracketprocess)s' # equivalent to [%(process)5s]
log_fmt_logfile: '%(asctime)s,%(msecs)03d [%(name)-17s][%(levelname)-8s] %(message)s'

log_granular_levels

Default: {}

这可以用来更具体地根据日志调用名称来控制日志记录级别。 该示例将Salt Master库设置为'警告'级别,将salt.modules设置为在调试级别进行日志记录,并将自定义模块设置为所有级别:

log_granular_levels:
  'salt': 'warning'
  'salt.modules': 'debug'
  'salt.loader.saltmaster.ext.module.custom_module': 'all'

3、外部日志记录处理程序

外部日志记录处理程序

除了salt使用的内部日志处理程序之外,还有一些可以使用的外部日志处理程序,如下所示,详情请参阅外部日志处理程序文档

fluent_mod

Fluent Logging Handler

log4mongo_mod

Log4Mongo Logging Handler

logstash_mod

Logstash Logging Handler

sentry_mod

Sentry Logging Handler

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值