https://github.com/acro5piano/knex-little-logger
Zero config queries logger for knex, aiming to replace knex-tiny-logger
https://github.com/acro5piano/knex-little-logger
knex logger mysql postgresql sqlite3 typescript
Last synced: 23 days ago
JSON representation
Zero config queries logger for knex, aiming to replace knex-tiny-logger
- Host: GitHub
- URL: https://github.com/acro5piano/knex-little-logger
- Owner: acro5piano
- License: mit
- Created: 2021-06-23T07:48:32.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-09T07:42:54.000Z (about 4 years ago)
- Last Synced: 2025-01-31T22:11:43.044Z (10 months ago)
- Topics: knex, logger, mysql, postgresql, sqlite3, typescript
- Language: TypeScript
- Homepage:
- Size: 82 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# knex-little-logger
[](https://github.com/acro5piano/knex-little-logger/actions/workflows/test.yml)

Zero config queries logger for knex.
The functionality is almost the same as [knex-tiny-logger](https://github.com/khmm12/knex-tiny-logger) which inspired knex-little-logger.

## Usage
Install the package:
```bash
$ yarn add knex-little-logger
```
Apply `knex-little-logger` to `knex` instance:
```js
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:
```js
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:
```js
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](LICENSE.md)