Cache logger instance.
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user