@debugr/mikroorm
TypeScript icon, indicating that this package has built-in type declarations

3.0.0-rc.7 • Public • Published

MikroORM plugin for Debugr

This plugin provides a Logger implementation compatible with MikroORM, allowing you to add SQL logging to your tasks.

Installation

npm install --save @debugr/mikroorm

Usage

import { Logger, LogLevel } from '@debugr/core';
import { MikroORMCollector } from '@debugr/mikroorm';
import { ConsoleHandler } from '@debugr/console';
import { MikroORM } from '@mikro-orm/core';

const globalContext = {
  applicationName: 'example',
};

const logger = new Logger(globalContext, [
  new ConsoleHandler({
    threshold: LogLevel.INFO,
  }),
  new MikroORMCollector(),
]);

// inject the plugin into your MikroORM connection options
const connection = await MikroORM.init({
  // ...
  getLogger() {
    return logger.getPlugin('mikroorm');
  },
});

Options

The MikroORMCollector constructor accepts an optional options object you can use to override the default mapping between MikroORM logger namespaces and log levels on the one hand and Debugr log levels on the other. MikroORM currently defines five logger namespaces and three log levels, which are by default mapped to Debugr log levels as follows:

const defaultNamespaceMap: MikroORMNamespaceMap = {
  discovery: LogLevel.DEBUG,
  info: LogLevel.INFO,
  query: LogLevel.INFO,
  'query-params': LogLevel.INFO,
  schema: LogLevel.INFO,
};

const defaultLevelMap: MikroORMLevelMap = {
  info: LogLevel.DEBUG,
  warning: LogLevel.WARNING,
  error: LogLevel.ERROR,
};

You can override any of these mappings using the optional namespaces and levels keys of the options object.

Readme

Keywords

none

Package Sidebar

Install

npm i @debugr/mikroorm

Weekly Downloads

0

Version

3.0.0-rc.7

License

MIT

Unpacked Size

12.7 kB

Total Files

8

Last publish

Collaborators

  • jahudka
  • marek.fiala