typeorm-logger-adaptor
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

typeorm-logger-adaptor

npm version

Logger adaptors for TypeORM.

Supported loggers

Install

# NPM
npm install typeorm-logger-adaptor

# Yarn
yarn add typeorm-logger-adaptor

How to use

  1. Install typeorm-logger-adaptor, typeorm and a logger library you want to use.
  2. import { XxxAdaptor } from 'typeorm-logger-adaptor/logger/xxx';.
    • Replace xxx with logger library name (e.g. winston, bunyan).
  3. Create and configure a logger instance.
  4. Create an adaptor instance and configure TypeORM connection.
    • See here for details.

Example

import { createConnection } from 'typeorm';
import * as winston from 'winston';
import { WinstonAdaptor } from 'typeorm-logger-adaptor/logger/winston';

// Configure logger (Winston)
const logger = winston.createLogger({
  level: 'debug',
  format: winston.format.cli(),
  transports: [new winston.transports.Console()],
});

const host = 'host';
const port = 3306;
const username = 'conn_user';
const password = 'conn_user_pw';
const database = 'db_name';

// Configure connection
createConnection({
  type: 'mysql',
  host,
  port,
  username,
  password,
  database,
  synchronize: true,
  migrationsRun: true,
  logger: new WinstonAdaptor(logger, 'all'),
})
  .then(async (conn) => {
    try {
      await conn.query('select 1');
    } finally {
      await conn.close();
    }
  })
  .catch((e) => console.error(e));

License

MIT License.

Copyright (c) 2020 KOMIYA Atsushi.

Package Sidebar

Install

npm i typeorm-logger-adaptor

Weekly Downloads

1,120

Version

1.1.0

License

MIT

Unpacked Size

34.3 kB

Total Files

27

Last publish

Collaborators

  • komiya-atsushi