# # # Nim's Runtime Library # (c) Copyright 2015 Andreas Rumpf, Dominik Picheta # # See the file "copying.txt", included in this # distribution, for details about the copyright. # ## This module implements a simple logger. It has been designed to be as simple ## as possible to avoid bloat, if this library does not fulfill your needs, ## write your own. ## ## Format strings support the following variables which must be prefixed with ## the dollar operator (``$``): ## ## ============ ======================= ## Operator Output ## ============ ======================= ## $date Current date ## $time Current time ## $datetime $dateT$time ## $app ``os.getAppFilename()`` ## $appname base name of $app ## $appdir directory name of $app ## $levelid first letter of log level ## $levelname log level name ## ============ ======================= ## ## ## The following example demonstrates logging to three different handlers ## simultaneously: ## ## .. code-block:: nim ## ## var L = newConsoleLogger() ## var fL = newFileLogger("test.log", fmtStr = verboseFmtStr) ## var rL = newRollingFileLogger("rolling.log", fmtStr = verboseFmtStr) ## addHandler(L) ## addHandler(fL) ## addHandler(rL) ## info("920410:52 accepted") ## warn("4 8 15 16 23 4-- Error") ## error("922044:16 SYSTEM FAILURE") ## fatal("SYSTEM FAILURE SYSTEM FAILURE") ## ## **Warning:** The global list of handlers is a thread var, this means that ## the handlers must be re-added in each thread. ## **Warning:** When logging on disk or console, only error and fatal messages ## are flushed out immediately. Use flushFile() where needed. import strutils, times when not defined(js): import os type Level* = enum ## logging level lvlAll, ## all levels active lvlDebug, ## debug level (and any above) active lvlInfo, ## info level (and any above) active lvlNotice, ## info notice (and any above) active lvlWarn, ## warn level (and any above) active lvlError, ## error level (and any above) active lvlFatal, ## fatal level (and any above) active lvlNone ## no levels active const LevelNames*: array[Level, string] = [ "DEBUG", "DEBUG", "INFO", "NOTICE", "WARN", "ERROR", "FATAL", "NONE" ] defaultFmtStr* = "$levelname " ## default format string verboseFmtStr* = "$levelid, [$datetime] -- $appname: " type Logger* = ref object of RootObj ## abstract logger; the base type of all loggers levelThreshold*: Level ## only messages of level >= levelThreshold ## should be processed fmtStr*: string ## = defaultFmtStr by default, see substituteLog for $date etc. ConsoleLogger* = ref object of Logger ## logger that writes the messages to the ## console when not defined(js): type FileLogger* = ref object of Logger ## logger that writes the messages to a file file*: File ## the wrapped file. RollingFileLogger* = ref object of FileLogger ## logger that writes the ## messages to a file and ## performs log rotation maxLines: int # maximum number of lines curLine : int baseName: string # initial filename baseMode: FileMode # initial file mode logFiles: int # how many log files already created, e.g. basename.1, basename.2... bufSize: int # size of output buffer (-1: use system defaults, 0: unbuffered, >0
type SomeBase* = ref object of RootObj
type SomeDerived* = ref object of SomeBase
memberProc*: proc ()
method testMethod(g: SomeBase) {.base, locks: "unknown".} = discard
method testMethod(g: SomeDerived) =
if g.memberProc != nil:
g.memberProc()
# ensure int literals still work
proc plain*() {.locks: 0.} =
discard