MySQL  8.0.22
Source Code Documentation
log_service_imp Class Reference

#include <log_service_imp.h>

Static Public Member Functions

static void init ()
 Initialize a loadable logging service. More...
 
static void exit ()
 De-initialize a loadable logging service. More...
 
static int run (void *instance, log_line *ll) noexcept
 Have the service process one log line. More...
 
static log_service_error flush (void **instance) noexcept
 Flush any buffers. More...
 
static log_service_error open (log_line *ll, void **instance) noexcept
 Open a new instance. More...
 
static log_service_error close (void **instance) noexcept
 Close and release an instance. More...
 
static int characteristics (void) noexcept
 Get characteristics of a log-service. More...
 
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. More...
 
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. More...
 

Member Function Documentation

◆ characteristics()

int log_service_imp::characteristics ( void  )
staticnoexcept

Get characteristics of a log-service.

Return values
<0an error occurred
>=0characteristics (a set of log_service_chistics flags)

◆ close()

log_service_error log_service_imp::close ( void **  instance)
staticnoexcept

Close and release an instance.

Flushes any buffers.

Parameters
instanceState-pointer that was returned on open. If memory was allocated for this state, it should be released, and the pointer set to nullptr.
Return values
<0an error occurred
=0success

Flushes any buffers.

Parameters
instanceState-pointer that was returned on open. If memory was allocated for this state, it should be released, and the pointer set to nullptr.
Return values
LOG_SERVICE_SUCCESSsuccess
otherwisean error occurred

Flushes any buffers.

Parameters
instanceState-pointer that was returned on open. If memory was allocated for this state, it should be released, and the pointer set to nullptr.
Return values
LOG_SERVICE_SUCCESS

◆ exit()

static void log_service_imp::exit ( )
static

De-initialize a loadable logging service.

◆ flush()

log_service_error log_service_imp::flush ( void **  instance)
staticnoexcept

Flush any buffers.

This function will be called by the server on FLUSH ERROR LOGS. The service may write its buffers, close and re-open any log files to work with log-rotation, etc. The flush function MUST NOT itself log anything! A service implementation may provide a nullptr if it does not wish to provide a flush function.

Parameters
instanceState-pointer that was returned on open. Value may be changed in flush.
Return values
<0an error occurred
=0no work was done
>0flush completed without incident

This function will be called by the server on FLUSH ERROR LOGS. The service may write its buffers, close and re-open any log files to work with log-rotation, etc. The flush function MUST NOT itself log anything! A service implementation may provide a nullptr if it does not wish to provide a flush function.

Parameters
instanceState-pointer that was returned on open. Value may be changed in flush.
Return values
LOG_SERVICE_NOTHING_DONEno work was done

This function will be called by the server on FLUSH ERROR LOGS. The service may write its buffers, close and re-open any log files to work with log-rotation, etc. The flush function MUST NOT itself log anything! A service implementation may provide a nullptr if it does not wish to provide a flush function.

Parameters
instanceState-pointer that was returned on open. Value may be changed in flush.
Return values
LOG_SERVICE_NOTHING_DONEno work was done
LOG_SERVICE_SUCCESSflush completed without incident
otherwisean error occurred

◆ get_log_name()

log_service_error log_service_imp::get_log_name ( void *  instance,
char *  buf,
size_t  bufsize 
)
staticnoexcept

Provide the name for a log file this service would access.

Parameters
instanceinstance info returned by open() if requesting the file-name for a specific open instance. nullptr to get the name of the default instance (even if it that log is not open). This is used to determine the name of the log-file to load on start-up.
bufAddress of a buffer allocated in the caller. The callee may return an extension starting with '.', in which case the path and file-name will be the system's default, except with the given extension. Alternatively, the callee may return a file-name which is assumed to be in the same directory as the default log. Values are C-strings.
bufsizeThe size of the allocation in the caller.
Return values
LOG_SERVICE_SUCCESSSuccess
LOG_SERVICE_UNSUPPORTED_MODEonly default/only instances supported
LOG_SERVICE_BUFFER_SIZE_INSUFFICIENT
LOG_SERVICE_MISC_ERROR
Parameters
instanceinstance info returned by open() if requesting the file-name for a specific open instance. nullptr to get the name of the default instance (even if it that log is not open). This is used to determine the name of the log-file to load on start-up.
bufAddress of a buffer allocated in the caller. The callee may return an extension starting with '.', in which case the path and file-name will be the system's default, except with the given extension. Alternatively, the callee may return a file-name which is assumed to be in the same directory as the default log. Values are C-strings.
bufsizeThe size of the allocation in the caller.
Return values
0Success
-1Mode not supported (only default / only instances supported)
-2Buffer not large enough
-3Misc. error

◆ init()

static void log_service_imp::init ( )
static

Initialize a loadable logging service.

◆ open()

log_service_error log_service_imp::open ( log_line ll,
void **  instance 
)
staticnoexcept

Open a new instance.

Parameters
lloptional arguments
instanceIf state is needed, the service may allocate and initialize it and return a pointer to it here. (This of course is particularly pertinent to components that may be opened multiple times, such as the JSON log writer.) This state is for use of the log-service component in question only and can take any layout suitable to that component's need. The state is opaque to the server/logging framework. It must be released on close.
Return values
<0a new instance could not be created
=0success, returned hande is valid
Parameters
lloptional arguments
instanceIf state is needed, the service may allocate and initialize it and return a pointer to it here. (This of course is particularly pertinent to components that may be opened multiple times, such as the JSON log writer.) This state is for use of the log-service component in question only and can take any layout suitable to that component's need. The state is opaque to the server/logging framework. It must be released on close.
Return values
LOG_SERVICE_SUCCESSsuccess, returned hande is valid
otherwisea new instance could not be created

◆ parse_log_line()

log_service_error log_service_imp::parse_log_line ( const char *  line_start,
size_t  line_length 
)
staticnoexcept

Parse a single line in an error log of this format.

(optional)

Parameters
line_startpointer to the beginning of the line ('{')
line_lengthlength of the line
Return values
0Success
!=0Failure (out of memory, malformed argument, etc.)
Parameters
line_startpointer to the beginning of the line ('{')
line_lengthlength of the line
Return values
0Success
!=0Failure (out of memory, malformed argument, etc.)

◆ run()

int log_service_imp::run ( void *  instance,
log_line ll 
)
staticnoexcept

Have the service process one log line.

services: log sinks: basic structured dump writer

services: log sinks: classic syslog/EventLog writer (message only) label will be ignored (one will be generated from priority by the syslogger).

services: log sinks: JSON structured dump writer Will write structured info to stderr/file.

services: log filter: basic filtering

If a run function wishes to itself use error logging in case of severe failure, it may do so after FIRST securing the all further calls to run() will be rejected. "log_sink_test" implements an example of this.

Parameters
instanceState-pointer that was returned on open.
llThe log_line collection of log_items.
Return values
<0an error occurred
=0no work was done
>0number of processed entities

The actual dragnet filtering engine is currently the default filter and therefore built-in (see components/mysql_server/log_builtins_filter.cc); this service is just a configuration language parser/compiler/decompiler; once it has set up the filter rule-set according to the user's instructions, it calls on the built-in engine to do the actual filtering.

Third parties could in theory write their own filtering language on top of that engine; they could also create their own filtering engine and use it instead of the provided one.

Parameters
llthe log line to filter
instanceinstance (unused in dragnet as it's not currently multi-open; we just always use log_filter_dragnet_rules)
Return values
intnumber of matched rules

Binary will be escaped according to JSON rules. If you should not be able to specify a label, one will be generated for you from the line's priority field.

Parameters
instanceinstance state
llthe log line to write
Return values
>=0number of accepted fields, if any
<0error

If the message is not \0 terminated, it will be terminated.

Parameters
instanceinstance's state
llthe log line to write
Return values
>=0number of accepted fields, if any
LOG_SERVICE_NOT_AVAILABLElog was not open
LOG_SERVICE_INVALID_ARGUMENTcould not sanitize log message
LOG_SERVICE_MISC_ERRORfailure not otherwise specified

This is intended for testing and debugging, not production.

Writes all fields. No escaping is done. Submits various events of its own to demonstrate the availability of the error event submission interface from within external service, as well as the correct functioning of said interface.

Parameters
instanceinstance
llthe log line to write
Return values
intnumber of accepted fields, if any
<0failure

The documentation for this class was generated from the following files: