Type alias DataAPILoggingConfig

Overview

The configuration for logging events emitted by the DataAPIClient.

This can be set at any level of the major class hierarchy, and will be inherited by all child classes.

Configuration inheritance

The logging config, at its core, is just a list of events to enable/disable, and where to emit/log them.

When they're inherited by child classes, it's done as a simple list merge, with the child's config taking precedence. (e.g. [...parentConfig, ...childConfig]). Each new layer of config is applied on top of the previous one, overwriting any previous settings for the same events.

Configuration & shorthands

There's multiple ways to configure logging, depending on how much control you want:

logging: 'all'

  • This will emit all events, but will also log some of them to the console
  • When you use just 'all', it simply replaces it with EventLoggingDefaults

logging: [{ events: 'all', emits: 'event' }]

  • This will emit all events, without logging any of them to the console

logging: '<command>' | ['<commands>']

  • This will emit only the events for the specified command, but may also log some of them to the console
  • Each command's behavior is listed below, & defined in EventLoggingDefaults

logging: ['all', [{ events: ['<commands>'], emits: [] }]]

  • This will emit all but the specified events, but will also log some of them to the console

Just keep in mind that it's really just a list of configuration "layers".

Event types

See DataAPIClientEventMap for more information on the types of events emitted.

Output types

The emits field can be set to either 'event', 'stdout', or 'stderr'.

  • 'event' will emit the event to the DataAPIClient instance
  • 'stdout' will log the event to stdout
  • 'stderr' will log the event to stderr

Examples

const client = new DataAPIClient('*TOKEN*', {
logging: [{ events: 'all', emits: 'stdout' }],
});
const db = client.db('*ENDPOINT*');

// Output:
// '[CommandStartedEvent]: createCollection in default_keyspace'
// '[CommandSucceededEvent]: createCollection in default_keyspace (took ...ms)'
await db.createCollection('my_collection');

See

  • DataAPIClientEventMap
  • DataAPILoggingEvent
  • DataAPILoggingOutput