Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.01 KB

File metadata and controls

44 lines (33 loc) · 1.01 KB
sidebar_position 15
description Setup logging

Logging

Logging can be enabled by passing a log option when creating a ZenStackClient instance. The log option can be a list of log levels, causing the client to log messages at those levels to the console:

const db = new ZenStackClient(..., {
  log: ['query', 'error'],
});

Or it can be a logging function that receives a log object with the following type:

// https://kysely.dev/docs/recipes/logging

interface LogEvent {
  // log level
  level: 'query' | 'error';

  // the query compiled by Kysely, including the SQL AST, raw SQL string, and parameters.
  query: CompiledQuery;
  
  // time taken to execute the query
  queryDurationMillis: number; 

  // error information, only present if `level` is `'error'`
  error: unknown;
}
const db = new ZenStackClient(..., {
  log: (event) => {
    console.log(`[${event.level}] ${event.queryDurationMillis}ms`);
  },
});

The log option is passed through to the underlying Kysely instance.