5.4.2.7 Error Logging in JSON FormatJSON格式的错误日志记录

This section describes how to configure error logging using the built-in filter, log_filter_internal, and the JSON sink, log_sink_json, to take effect immediately and for subsequent server startups. 本节介绍如何使用内置筛选器log_filter_internal和JSON接收器log_sink_json配置错误日志记录,以便立即生效并用于后续服务器启动。For general information about configuring error logging, see Section 5.4.2.1, “Error Log Configuration”.有关配置错误日志的一般信息,请参阅第5.4.2.1节,“错误日志配置”

To enable the JSON sink, first load the sink component, then modify the log_error_services value:要启用JSON接收器,请首先加载接收器组件,然后修改log_error_services值:

INSTALL COMPONENT 'file://component_log_sink_json';
SET PERSIST log_error_services = 'log_filter_internal; log_sink_json';

To set log_error_services to take effect at server startup, use the instructions at Section 5.4.2.1, “Error Log Configuration”. 要将log_error_services设置为在服务器启动时生效,请使用第5.4.2.1节,“错误日志配置”中的说明。Those instructions apply to other error-logging system variables as well.这些说明也适用于其他错误记录系统变量。

It is permitted to name log_sink_json multiple times in the log_error_services value. 允许在log_error_services值中多次命名log_sink_jsonFor example, to write unfiltered events with one instance and filtered events with another instance, you could set log_error_services like this:例如,要用一个实例编写未筛选的事件,用另一个实例写入已筛选的事件。您可以这样设置log_error_services

SET PERSIST log_error_services = 'log_sink_json; log_filter_internal; log_sink_json';

The JSON sink determines its output destination based on the default error log destination, which is given by the log_error system variable. JSON接收器根据log_error系统变量给定的默认错误日志目的地来确定其输出目的地。If log_error names a file, the JSON sink bases output file naming on that file name, plus a numbered .NN.json suffix, with NN starting at 00. 如果log_error命名一个文件,JSON接收器会根据该文件名加上编号的NN.json后缀来命名输出文件,NN从00开始。For example, if log_error is file_name, successive instances of log_sink_json named in the log_error_services value write to file_name.00.json, file_name.01.json, and so forth.例如,如果log_errorfile_name,则log_error_services值中命名的log_sink_json的连续实例将写入file_name.00.jsonfile_name.01.json等。

If log_error is stderr, the JSON sink writes to the console. 如果log_errorstderr,JSON接收器将写入控制台。If log_sink_json is named multiple times in the log_error_services value, they all write to the console, which is likely not useful.如果在log_error_services值中多次命名log_sink_json,那么它们都会写入控制台,这可能没有用处。