Logging
Enabling logging
You can enable logging of all queries and errors by simply setting logging: true
in data source options:
Logging options
You can enable different types of logging in data source options:
If you want to enable logging of failed queries only then only add error
:
There are other options you can use:
query
- logs all queries.error
- logs all failed queries and errors.schema
- logs the schema build process.warn
- logs internal orm warnings.info
- logs internal orm informative messages.log
- logs internal orm log messages.
You can specify as many options as needed. If you want to enable all logging you can simply specify logging: "all"
:
Log long-running queries
If you have performance issues, you can log queries that take too much time to execute by setting maxQueryExecutionTime
in data source options:
This code will log all queries which run for more than 1 second
.
Changing default logger
TypeORM ships with 4 different types of logger:
advanced-console
- this is the default logger which logs all messages into the console using color and sql syntax highlighting (using chalk).simple-console
- this is a simple console logger which is exactly the same as the advanced logger, but it does not use any color highlighting. This logger can be used if you have problems / or don't like colorized logs.file
- this logger writes all logs intoormlogs.log
in the root folder of your project (nearpackage.json
).debug
- this logger uses debug package, to turn on logging set your env variableDEBUG=typeorm:*
(note logging option has no effect on this logger).
You can enable any of them in data source options:
Using custom logger
You can create your own logger class by implementing the Logger
interface:
Or you can extend the AbstractLogger
class:
And specify it in data source options:
Logger methods can accept QueryRunner
when it's available. It's helpful if you want to log additional data. Also, via query runner, you can get access to additional data passed during to persist/remove. For example:
Last updated