Skip to content

acro5piano/knex-little-logger

Repository files navigation

knex-little-logger

test npm (tag)

Zero config queries logger for knex.

The functionality is almost the same as knex-tiny-logger which inspired knex-little-logger.

Usage

Install the package:

$ yarn add knex-little-logger

Apply knex-little-logger to knex instance:

import createKnex from 'knex'
import { knexLittleLogger } from 'knex-little-logger'

const knexOptions = {} // Your knex config
const knex = createKnex(knexOptions)
knexLittleLogger(knex)

// alternative
// knex-little-logger returns knex instance
// so you can do like this
const knex = knexLittleLogger(createKnex(knexOptions))

Advanced usage

By default knex-little-logger uses console.log, but you can specify any logger which your prefer:

import createKnex from 'knex'
import { knexLittleLogger } from 'knex-little-logger'
import initDebug from 'debug'

const awesomeLogger = initDebug('my-project:knex')
const knexOptions = {} // Your knex config
const knex = createKnex(knexOptions)
knexLittleLogger(knex, { logger: awesomeLogger })

Also you can disable bindings:

knexLittleLogger(knex, { bindings: false })

Difference from knex-tiny-logger

knex-little-logger does:

  • Use BigInt to measure time
  • Written in TypeScript
  • Binding works
  • Add the option to disable colorized logs
  • Not works for knex <= 0.95.0
  • Not depends on the knex internal api

License

MIT