Migrate to namespaced_logging v2.

This commit is contained in:
2025-07-12 07:54:13 -05:00
parent aa02f9f5b1
commit b8c64cc693
4 changed files with 17 additions and 10 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
*.sw?
nimcache/
nimble.develop
nimble.paths

View File

@ -1,6 +1,6 @@
# Package
version = "3.1.1"
version = "3.2.0"
author = "Jonathan Bernard"
description = "Lightweight Postgres ORM for Nim."
license = "GPL-3.0"
@ -11,4 +11,4 @@ srcDir = "src"
# Dependencies
requires @["nim >= 1.4.0", "uuids"]
requires "namespaced_logging >= 1.0.0"
requires "namespaced_logging >= 2.0.2"

View File

@ -302,25 +302,30 @@ type
records*: seq[T]
totalRecords*: int
DbUpdateError* = object of CatchableError ##\
DbUpdateError* = object of CatchableError
## Error types raised when a DB modification fails.
NotFoundError* = object of CatchableError ##\
NotFoundError* = object of CatchableError
## Error type raised when no record matches a given ID
var logService {.threadvar.}: Option[LogService]
var logService {.threadvar.}: Option[ThreadLocalLogService]
var logger {.threadvar.}: Option[Logger]
proc makeQueryLogEntry(
m: string,
sql: string,
args: openArray[(string, string)] = []): JsonNode =
result = %*{ "method": m, "sql": sql }
for (k, v) in args: result[k] = %v
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
logger.debug(log)
logger.debug(makeQueryLogEntry(methodName, sqlStmt, args))
proc enableDbLogging*(svc: LogService) =
proc enableDbLogging*(svc: ThreadLocalLogService) =
logService = some(svc)
proc newMutateClauses(): MutateClauses =

View File

@ -4,7 +4,7 @@
## Simple database connection pooling implementation compatible with Fiber ORM.
import std/[sequtils, strutils, sugar]
import std/[sequtils, sugar]
import db_connector/db_common
from db_connector/db_sqlite import getRow, close