MySQL 9.0.0
Source Code Documentation
log_sink_json.cc File Reference
#include <mysql/components/services/log_builtins.h>
#include <mysql/components/services/log_shared.h>
#include <mysql/components/services/log_sink_perfschema.h>
#include <string>
#include "log_service_imp.h"
#include "my_compiler.h"
#include "my_rapidjson_size_t.h"
#include <rapidjson/document.h>

Classes

struct  my_state
 

Macros

#define WITH_PFS_SUPPORT
 This is a "modern" log writer, i.e. More...
 
#define WITH_LOG_PARSER
 
#define LOG_EXT   ".json"
 Log-file extension. More...
 
#define MY_RAPID_INT(key, val, dflt)
 
#define MY_RAPID_STR(key, val, len)
 

Enumerations

enum  enum_log_json_pretty_print { JSON_NOSPACE = 0 , JSON_PAD = 1 , JSON_MULTILINE = 2 }
 Pretty-print (with indents and line-breaks between key/value pairs), or one event per line? jq for example doesn't mind, but we play it safe by defaulting to the latter; this is also the format that "journalctl -o json" renders on platforms that use systemd's journal. More...
 

Functions

 REQUIRES_SERVICE_PLACEHOLDER (log_builtins)
 
 REQUIRES_SERVICE_PLACEHOLDER (log_builtins_string)
 
 REQUIRES_SERVICE_PLACEHOLDER (log_sink_perfschema)
 
static log_service_error get_json_log_name (void *instance, char *buf, size_t bufsize)
 
mysql_service_status_t log_service_exit ()
 De-initialization method for Component used when unloading the Component. More...
 
mysql_service_status_t log_service_init ()
 Initialization entry method for Component used when loading the Component. More...
 
 PROVIDES_SERVICE (log_sink_json, log_service)
 
 END_COMPONENT_PROVIDES ()
 
 REQUIRES_SERVICE (log_builtins)
 
 REQUIRES_SERVICE (log_builtins_string)
 
 REQUIRES_SERVICE (log_sink_perfschema)
 
 END_COMPONENT_REQUIRES ()
 
 METADATA ("mysql.author", "Oracle Corporation")
 
 METADATA ("mysql.license", "GPL")
 
 METADATA ("log_service_type", "sink")
 
 END_COMPONENT_METADATA ()
 

Variables

const mysql_service_log_builtins_tlog_bi = nullptr
 accessor built-ins More...
 
const mysql_service_log_builtins_string_tlog_bs = nullptr
 string built-ins More...
 
const mysql_service_log_sink_perfschema_tlog_ps = nullptr
 
static bool inited = false
 
static int opened = 0
 
static enum_log_json_pretty_print pretty = JSON_PAD
 
const mysql_service_log_service_t imp_log_sink_json_log_service
 
mysql_component_t mysql_component_log_sink_json
 

Macro Definition Documentation

◆ LOG_EXT

#define LOG_EXT   ".json"

Log-file extension.

◆ MY_RAPID_INT

#define MY_RAPID_INT (   key,
  val,
  dflt 
)
Value:
ulonglong val = dflt; \
iter = document.FindMember(key); \
if ((iter != document.MemberEnd()) && iter->value.IsInt()) \
val = iter->value.GetInt();
unsigned long long int ulonglong
Definition: my_inttypes.h:56
required string key
Definition: replication_asynchronous_connection_failover.proto:60

◆ MY_RAPID_STR

#define MY_RAPID_STR (   key,
  val,
  len 
)
Value:
const char *val = nullptr; \
size_t len = 0; \
iter = document.FindMember(key); \
if ((iter != document.MemberEnd()) && iter->value.IsString()) { \
val = iter->value.GetString(); \
len = iter->value.GetStringLength(); \
}

◆ WITH_LOG_PARSER

#define WITH_LOG_PARSER

◆ WITH_PFS_SUPPORT

#define WITH_PFS_SUPPORT

This is a "modern" log writer, i.e.

it doesn't care what type a log_item on an error log event is; as long as it's one of the wellknown classes (string, float, int), it can and will write it.

By default, each line will contain one log event, in a format somewhat similar to that emitted by "journalctl -o json" on platforms that use systemd's journal:

{ "prio" : 2, "err_code" : 3581, "msg" : "Parser saw: SET @@global.log_error_filter_rules= DEFAULT", "err_symbol" : "ER_PARSER_TRACE", "label" : "Note" } { "prio" : 2, "err_code" : 3581, "subsystem" : "parser", "SQL_state" : "XX999", "source_file" : "sql_parse", "function" : "dispatch_command", "msg" : "Parser saw: SELECT \"logging as traditional MySQL error log and as JSON"", "time" : "1970-01-01T00:00:00.000000Z", "thread" : 0, "err_symbol" : "ER_PARSER_TRACE", "label" : "Note" }

Enumeration Type Documentation

◆ enum_log_json_pretty_print

Pretty-print (with indents and line-breaks between key/value pairs), or one event per line? jq for example doesn't mind, but we play it safe by defaulting to the latter; this is also the format that "journalctl -o json" renders on platforms that use systemd's journal.

Enumerator
JSON_NOSPACE 

emit no whitespace padding

JSON_PAD 

similar to systemd's journal

JSON_MULTILINE 

multi-line pretty-print

Function Documentation

◆ END_COMPONENT_METADATA()

END_COMPONENT_METADATA ( )

◆ END_COMPONENT_PROVIDES()

END_COMPONENT_PROVIDES ( )

◆ END_COMPONENT_REQUIRES()

END_COMPONENT_REQUIRES ( )

◆ get_json_log_name()

static log_service_error get_json_log_name ( void *  instance,
char *  buf,
size_t  bufsize 
)
static

◆ log_service_exit()

mysql_service_status_t log_service_exit ( )

De-initialization method for Component used when unloading the Component.

Returns
Status of performed operation
Return values
falsesuccess
truefailure

◆ log_service_init()

mysql_service_status_t log_service_init ( )

Initialization entry method for Component used when loading the Component.

Returns
Status of performed operation
Return values
falsesuccess
truefailure

◆ METADATA() [1/3]

METADATA ( "log_service_type"  ,
"sink"   
)

◆ METADATA() [2/3]

METADATA ( "mysql.author"  ,
"Oracle Corporation"   
)

◆ METADATA() [3/3]

METADATA ( "mysql.license"  ,
"GPL"   
)

◆ PROVIDES_SERVICE()

PROVIDES_SERVICE ( log_sink_json  ,
log_service   
)

◆ REQUIRES_SERVICE() [1/3]

REQUIRES_SERVICE ( log_builtins  )

◆ REQUIRES_SERVICE() [2/3]

REQUIRES_SERVICE ( log_builtins_string  )

◆ REQUIRES_SERVICE() [3/3]

REQUIRES_SERVICE ( log_sink_perfschema  )

◆ REQUIRES_SERVICE_PLACEHOLDER() [1/3]

REQUIRES_SERVICE_PLACEHOLDER ( log_builtins  )

◆ REQUIRES_SERVICE_PLACEHOLDER() [2/3]

REQUIRES_SERVICE_PLACEHOLDER ( log_builtins_string  )

◆ REQUIRES_SERVICE_PLACEHOLDER() [3/3]

REQUIRES_SERVICE_PLACEHOLDER ( log_sink_perfschema  )

Variable Documentation

◆ imp_log_sink_json_log_service

const mysql_service_log_service_t imp_log_sink_json_log_service
Initial value:
= {
static log_service_error get_log_name(void *instance, char *buf, size_t bufsize) noexcept
Provide the name for a log file this service would access.
Definition: log_sink_json.cc:456
static log_service_error open(log_line *ll, void **instance) noexcept
Open a new instance.
Definition: log_filter_dragnet.cc:1571
static int characteristics(void) noexcept
Get characteristics of a log-service.
Definition: log_filter_dragnet.cc:1626
static int run(void *instance, log_line *ll) noexcept
Have the service process one log line.
Definition: log_filter_dragnet.cc:1548
static log_service_error flush(void **instance) noexcept
Flush any buffers.
Definition: log_filter_dragnet.cc:1616
static log_service_error close(void **instance) noexcept
Close and release an instance.
Definition: log_filter_dragnet.cc:1592
static log_service_error parse_log_line(const char *line_start, size_t line_length) noexcept
Parse a single line in an error log of this format.
Definition: log_sink_json.cc:126

◆ inited

bool inited = false
static

◆ log_bi

accessor built-ins

◆ log_bs

string built-ins

◆ log_ps

◆ mysql_component_log_sink_json

mysql_component_t mysql_component_log_sink_json
Initial value:
= { "mysql:log_sink_json" , __log_sink_json_provides, __log_sink_json_requires, __log_sink_json_metadata,
mysql_service_status_t log_service_exit()
De-initialization method for Component used when unloading the Component.
Definition: log_sink_json.cc:592
mysql_service_status_t log_service_init()
Initialization entry method for Component used when loading the Component.
Definition: log_sink_json.cc:608

◆ opened

int opened = 0
static

◆ pretty