// Define a custom formatter
const customFormatter: EventFormatter = (event, message) => {
return `[${event.requestId.slice(0, 8)}] (${event.name}) - ${message}`;
}
// Set the custom formatter as the default
BaseClientEvent.setDefaultFormatter(customFormatter);
// Now all events will use the custom formatter
const coll = db.collection('*COLLECTION_NAME*', {
logging: [{ events: 'all', emits: 'stdout' }],
});
// Logs:
// - [e31bc40e] (CommandStarted) - (default_keyspace.basic_logging_example_table) findOne
// - [e31bc40e] (CommandFailed) - (default_keyspace.basic_logging_example_table) findOne (took 249ms) - 'Invalid filter expression: filter clause path ('$invalid') contains character(s) not allowed'
coll.findOne({ $invalid: 1 });
Overview
A function that formats an event into a string.
Used with BaseClientEvent.format, which dictates how the event should be logged to stdout/stderr.
There are two ways to use this method:
Default format
The default format is
[timestamp] [requestId[0..8]] [eventName]: message
.timestamp
is of the formatYYYY-MM-DD HH:MM:SS TZ
.requestId
is the first 8 characters of the requestId.eventName
is the name of the event.message
is the message generated by the event.For example:
Custom formatter example