Cache logger instance.
This commit is contained in:
parent
af44d48df1
commit
9d1cc4bbec
@ -1,6 +1,6 @@
|
||||
# Package
|
||||
|
||||
version = "3.1.0"
|
||||
version = "3.1.1"
|
||||
author = "Jonathan Bernard"
|
||||
description = "Lightweight Postgres ORM for Nim."
|
||||
license = "GPL-3.0"
|
||||
|
@ -309,14 +309,16 @@ type
|
||||
## Error type raised when no record matches a given ID
|
||||
|
||||
var logService {.threadvar.}: Option[LogService]
|
||||
var logger {.threadvar.}: Option[Logger]
|
||||
|
||||
proc logQuery*(methodName: string, sqlStmt: string, args: openArray[(string, string)] = []) =
|
||||
# namespaced_logging would do this check for us, but we don't want to even
|
||||
# build the log object if we're not actually logging
|
||||
if logService.isNone: return
|
||||
if logger.isNone: logger = logService.getLogger("fiber_orm/query")
|
||||
var log = %*{ "method": methodName, "sql": sqlStmt }
|
||||
for (k, v) in args: log[k] = %v
|
||||
logService.getLogger("fiber_orm/query").debug(log)
|
||||
logger.debug(log)
|
||||
|
||||
proc enableDbLogging*(svc: LogService) =
|
||||
logService = some(svc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user