Add autoconfigured, multithreaded example to README.
This commit is contained in:
32
README.md
32
README.md
@ -44,10 +44,11 @@ let dbLogger = getLogger("app/db/queryplanner")
|
||||
dbLogger.debug("Beginning query plan...")
|
||||
|
||||
# native support for structured logs (import std/json)
|
||||
dbLogger.debug(%{
|
||||
dbLogger.debug(%*{
|
||||
"method": "parseParams",
|
||||
"message": "unrecognized param type",
|
||||
"invalidType": params[idx].type
|
||||
"invalidType": $params[idx].type,
|
||||
"metadata": %(params.meta)
|
||||
} )
|
||||
```
|
||||
|
||||
@ -70,6 +71,33 @@ let apiLogger = localLogSvc.getLogger("api")
|
||||
let dbLogger = localLogSvc.getLogger("db")
|
||||
```
|
||||
|
||||
### Autoconfigured Multithreaded Application
|
||||
```nim
|
||||
import namespaced_logging/autoconfigured
|
||||
import mummy, mummy/routers
|
||||
|
||||
# Main thread setup
|
||||
addLogAppender(initConsoleLogAppender())
|
||||
|
||||
proc createApiRouter*(apiCtx: ProbatemApiContext): Router =
|
||||
# This will run on a separate thread, but the thread creation is managed by
|
||||
# mummy, not us. Log functions still operate correctly and respect the
|
||||
# configuration setup on the main thread
|
||||
let logger = getLogger("api")
|
||||
logger.trace(%*{ "method_entered": "createApiRouter" })
|
||||
|
||||
# API route setup...
|
||||
|
||||
logger.debug(%*{ "method": "createApiRouter", "routes": numRoutes })
|
||||
|
||||
|
||||
let server = newServer(createApiRouter(), workerThreads = 4)
|
||||
info("Serving MyApp v1.0.0 on port 8080")
|
||||
|
||||
setThreshold("api", lvlTrace) # will be picked up by loggers on worker threads
|
||||
```
|
||||
|
||||
|
||||
### Manual Multithreaded Application
|
||||
```nim
|
||||
import namespaced_logging
|
||||
|
Reference in New Issue
Block a user