/ chronicles / dynamic_scope_types.nim
dynamic_scope_types.nim
1 import ./[options, topics_registry] 2 3 when defined(js): 4 type UncheckedArray[T] = seq[T] 5 6 template select(LogRecord, A, B: typedesc): typedesc = 7 # When runtime filtering is enabled and we have more than one sink, we must 8 # pass the "enabled-or-not" bitmask to all functions so that they can forward 9 # to the sinks that are actually enabled 10 # If this when is inlined in the type definition, it runs afould of some 11 # evaluation order issue and selects the wrong type 12 when LogRecord is tuple and runtimeFilteringEnabled: B else: A 13 14 type 15 ScopeBindingBase*[LogRecord] = object of RootObj 16 name*: string 17 when (NimMajor, NimMinor) >= (2, 2): 18 appender*: select(LogRecord, LogAppender[LogRecord], MultiLogAppender[LogRecord]) 19 else: 20 appender*: pointer 21 22 LogAppender*[LogRecord] = 23 proc(x: var LogRecord, valueAddr: ptr ScopeBindingBase[LogRecord]) {.nimcall.} 24 25 MultiLogAppender*[LogRecord] = proc( 26 x: var LogRecord, valueAddr: ptr ScopeBindingBase[LogRecord], enabled: SinksBitmask 27 ) {.nimcall.} 28 29 ScopeBinding*[LogRecord, T] = object of ScopeBindingBase[LogRecord] 30 value*: T 31 32 BindingsArray*[LogRecord] = ptr UncheckedArray[ptr ScopeBindingBase[LogRecord]] 33 34 BindingsFrame*[LogRecord] = object 35 prev*: ptr BindingsFrame[LogRecord] 36 bindings*: BindingsArray[LogRecord] 37 bindingsCount*: int