question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Knex calling the global console (use of console.log internally)

See original GitHub issue

While a very useful library, I see several uses of console.log, console.error etc internally, which I cannot catch without overriding the global object. Is there any way to specify my own logging mechanism within knex (for example: winston loggers)?

Please see specific examples here and here.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

7reactions
dbettinicommented, Apr 7, 2018

@tgriesser I see you made a commit which adds setLogger, will it be merged soon or is there something blocking it?

2reactions
oiimecommented, Jul 11, 2016

Yeah, the most reasonable thing to do would be to inject an alternative logger when building a knex instance

eg: const logger = require('bunyan').createLogger({}) const knex = Knex({client: 'x', connection: {}, logger: logger)

where logger defaults to console, if a logger is assigned I think the default behavior should be to log all events and let the logger figure out the log level. it’ll be quite messy if it’ll requires passing .debug(true) to every query. I can write a patch for that if you’d like.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using console log in Knex migration not logging
Migrated Migration Done. These logs come from our migration script where we call database.migrate.latest(). My expected terminal output for the ...
Read more >
Installation | Knex.js
Knex can be used as an SQL query builder in both Node.JS and the browser, limited to WebSQL's constraints (like the inability to...
Read more >
Solving 14 SQL Exercises with Knex.JS - Ynon Perek
select('*'); console.log(users); knex.destroy(); } main();. Calling destroy at the end closes all connections to the database and ...
Read more >
Building a RESTful API with Koa and Postgres - Michael Herman
const server = app.listen(PORT, () => { console.log(`Server listening on ... Install Knex globally as well so you can use the CLI tool:....
Read more >
Tutorial: Setting up Node.js with a database - Medium
In this tutorial, I will show how to setup MySQL with Node using Knex in order to create a crude ... Check your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found