winston-knexdeprecated

Winston Transport for Knex JS

Usage no npm install needed!

<script type="module">
  import winstonKnex from 'https://cdn.skypack.dev/winston-knex';
</script>

README

Winston Transport for Knex

npm npm Codecov GitHub Release Date GitHub code size in bytes GitHub

Currently a work in progress

  • Supports Winston 3.x
  • Typescript typings built-in
  • Pure Knex

Installation

$ npm install winston-knex
# OR IF YOU PREFER YARN
$ yarn add winston-knex

Please also add your working database as dependency as described by Knex's documentation:

$ npm install pg
$ npm install sqlite3
$ npm install mysql
$ npm install mysql2
$ npm install oracledb
$ npm install mssql

Usage

const winston = require('winston')
const KnexTransport = require('winston-knex')

const logger = winston.createLogger({
  level: 'info',
  transports: [
    new KnexTransport({
      client: 'mysql',
      connection: 'mysql://user:password@host:port/dbname',
      tableName: 'anyname' // defaults to `logs`
      // this config also accepts any knex configuration key/params
    })
  ]
})

logger.error('This should inserted into the database')
logger.log({
  level: 'info',
  message: 'This should do as well'
})

Other methods such as stream is not written yet. You can only do query function with limited possibility.

TODO

  • Streaming logs (stream function)
  • Querying logs (query function) - ⚠ Need tests
  • Close connection (close function)

To get the logs values, please use knex for now: (there are more way of doing this, mine is just an example)

const knex = require('knex')({ ...config })

async function getLogsValue() {
  try {
    const trxProvider = knex.transactionProvider();
    const trx = await trxProvider();
    const logs = await trx('tableName').select();
    return logs;
  } catch (error) {
    throw new Error(error)
  }
}

Contributing

I will put this simply: Go ahead 😀

License

MIT