WL#9343: Logging services: log writers

Affects: Server-8.0   —   Status: Complete

LOG WRITERS

Log writers are services that accept a log event (a collection of 
key/value pairs describing a log event; at minimum a message and a priority) and 
write them to a log (a file, syslog, EventLog, etc.).

Re-implement logging (basic logging to file, logging to syslog/eventlog) as 
services using structured logging as per WL#9323 et al. on top of the 
new services model (as per WL#4102 et al.).

Additionally, implement at least one writer that can write all the structured 
data and item types supported by the new model, so that we may test.



EXAMPLE

I   "Traditional" MySQL error log

Fixed selection of infobits (timestamp, connection-ID, severity-label (Note, 
Warning, Error), error message) in fixed order:

2016-10-11T08:38:55.495001Z 25 [Note] mysqld (mysqld 8.0.0-dmr-debug) starting 
as 
process 7091 ...


II  JSON writer

Arbitrary key/value pairs can be logged; keys become tags, values their content. 
Order is irrelevant as items are not identified by order, but by key. Entities 
are escaped according to standard (in this example, ", others are 
supported, but not shown here). "One tag per line" organization facilitates 
easier debugging through more meaningful diffs. Writer is future-proof as it 
writes items according to their storage class (string, integer, or floating 
point number), not according to their semantics (error number, error message, 
etc.). Being able to handle new types of field therefore adds no complexity and 
requires no change in the source. Therefore, what is logged depends not on the 
capabilities of the writer, but on what information is submitted when the error 
event is created (give or take any filtering along the way). The richer the 
created event, the richer the output in the JSON log. This example shows the 
output of a debug helper that echos every line the parser sees to the error log.

{ "log_priority": 2,
  "subsystem": "parser",
  "SQL_state": "XX999",
  "source_file": "sql_parse",
  "time": "2016-10-11T08:38:55.495001Z",
  "thread": 25,
  "MySQL_err_symbol": "ER_PARSER_TRACE",
  "log_message": "Parser saw: INSTALL COMPONENT 
\"file://component_log_sink_json\"",
  "log_label": "Note" }

* Note that in this example, all keys are rather verbose for easier reading. An 
actual implementation might choose more concise keys to cut down on log file 
size.