mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-11-05 06:03:15 -06:00
abstract logger
This commit is contained in:
parent
c01c5309f5
commit
e134e37d5d
4 changed files with 67 additions and 27 deletions
|
@ -8,5 +8,5 @@ buildNimblePackage {
|
||||||
verions = "unstable";
|
verions = "unstable";
|
||||||
src = lib.cleanSource ./.;
|
src = lib.cleanSource ./.;
|
||||||
nativeBuildInputs = [ openssl ];
|
nativeBuildInputs = [ openssl ];
|
||||||
nimbleDepsHash = "sha256-3p+PdGkQmKwz5tzJwX0aun3kSOLw/lwzqRkR9+6ECQE=";
|
nimbleDepsHash = "sha256-RceRnhEkei3RfSCTOJsIiw4GSCyhOZhKoEVHNSw/KvA=";
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,12 @@
|
||||||
},
|
},
|
||||||
"hwylterm": {
|
"hwylterm": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"vcsRevision": "d852761831bd748db24b42f15bc8e2d286232295",
|
"vcsRevision": "7e82f7ba5a24d816a79b3a5ea49f32b4c7a5ef7e",
|
||||||
"url": "https://github.com/daylinmorgan/hwylterm",
|
"url": "https://github.com/daylinmorgan/hwylterm",
|
||||||
"downloadMethod": "git",
|
"downloadMethod": "git",
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"checksums": {
|
"checksums": {
|
||||||
"sha1": "7de2a93a03bd0659d8d70cc7c08315e0a7f15439"
|
"sha1": "d6d97bdff3fcdfcf4b39b144fa5f27a6b9f9494d"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"jsony": {
|
"jsony": {
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
## nix begat oizys
|
## nix begat oizys
|
||||||
import std/[os, tables, sequtils, strformat, strutils]
|
import std/[os, tables, sequtils, strformat, strutils]
|
||||||
import hwylterm, hwylterm/[cligen, logging]
|
import hwylterm, hwylterm/[cligen, logging]
|
||||||
import oizys/[context, github, nix, overlay]# 3, logging
|
import oizys/[context, github, nix, overlay, logging]
|
||||||
|
|
||||||
addHandler(
|
|
||||||
newFancyConsoleLogger(
|
|
||||||
fmtPrefix = $bb"[b magenta]oizys"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
proc confirm(q: string): bool =
|
proc confirm(q: string): bool =
|
||||||
stderr.write $(q & bb"[yellow] (Y/n) ")
|
stderr.write $(q & bb"[yellow] (Y/n) ")
|
||||||
|
@ -28,7 +23,7 @@ overlay:
|
||||||
resetCache: bool = false,
|
resetCache: bool = false,
|
||||||
rest: seq[string],
|
rest: seq[string],
|
||||||
) =
|
) =
|
||||||
if not debug: setLogFilter(lvlInfo)
|
setupLoggers(debug)
|
||||||
updateContext(host, flake, debug, resetCache)
|
updateContext(host, flake, debug, resetCache)
|
||||||
|
|
||||||
proc dry(minimal: bool = false) =
|
proc dry(minimal: bool = false) =
|
||||||
|
@ -82,16 +77,16 @@ proc checkExes() =
|
||||||
if findExe("nix") == "":
|
if findExe("nix") == "":
|
||||||
fatalQuit "oizys requires nix"
|
fatalQuit "oizys requires nix"
|
||||||
|
|
||||||
func `//`[A, B](pairs: openArray[(A, B)]): Table[A, B] =
|
# func `//`[A, B](pairs: openArray[(A, B)]): Table[A, B] =
|
||||||
pairs.toTable()
|
# pairs.toTable()
|
||||||
func `//`[A, B](t1: var Table[A,B], t2: Table[A,B]) =
|
# func `//`[A, B](t1: var Table[A,B], t2: Table[A,B]) =
|
||||||
for k, v in t2.pairs(): t1[k] = v
|
# for k, v in t2.pairs(): t1[k] = v
|
||||||
func `//`[A, B](t1: Table[A, B], t2: Table[A, B]): Table[A, B] =
|
# func `//`[A, B](t1: Table[A, B], t2: Table[A, B]): Table[A, B] =
|
||||||
result // t1; result // t2
|
# result // t1; result // t2
|
||||||
func `//`[A, B](pairs: openArray[(A,B)], t2: Table[A,B]): Table[A,B] =
|
# func `//`[A, B](pairs: openArray[(A,B)], t2: Table[A,B]): Table[A,B] =
|
||||||
// pairs // t2
|
# // pairs // t2
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import cligen
|
import cligen
|
||||||
|
@ -116,16 +111,16 @@ when isMainModule:
|
||||||
} // sharedHelp
|
} // sharedHelp
|
||||||
let
|
let
|
||||||
# clUse must be set here using clCfg doesn't seem to work with dispatchMutli ...
|
# clUse must be set here using clCfg doesn't seem to work with dispatchMutli ...
|
||||||
clUse* = $bb("$command $args\n${doc}[bold]Options[/]:\n$options")
|
# clUse* = $bb("$command $args\n${doc}[bold]Options[/]:\n$options")
|
||||||
osUsage = $bb("$command [[subcmd] $args\n$doc[bold]Options[/]:\n$options")
|
osUsage = $bb("$command [[subcmd] $args\n$doc[bold]Options[/]:\n$options")
|
||||||
|
|
||||||
dispatchMulti(
|
dispatchMulti(
|
||||||
[build, help = sharedHelp, usage = clUse ],
|
[build, help = sharedHelp, usage = clCfg.use ],
|
||||||
[cache, help = cacheHelp , usage = clUse ],
|
[cache, help = cacheHelp , usage = clCfg.use ],
|
||||||
[ci, help = ciHelp , usage = clUse ],
|
[ci, help = ciHelp , usage = clCfg.use ],
|
||||||
[dry, help = sharedHelp, usage = clUse ],
|
[dry, help = sharedHelp, usage = clCfg.use ],
|
||||||
[osCmd, help = sharedHelp, usage = osUsage, cmdName = "os"],
|
[osCmd, help = sharedHelp, usage = osUsage, cmdName = "os"],
|
||||||
[output, help = sharedHelp, usage = clUse],
|
[output, help = sharedHelp, usage = clCfg.use],
|
||||||
[update, help = updateHelp, usage = clUse],
|
[update, help = updateHelp, usage = clCfg.use],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
45
pkgs/oizys-nim/src/oizys/logging.nim
Normal file
45
pkgs/oizys-nim/src/oizys/logging.nim
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
## nix begat oizys
|
||||||
|
import std/[logging, os]
|
||||||
|
import hwylterm, hwylterm/logging
|
||||||
|
export logging
|
||||||
|
|
||||||
|
|
||||||
|
proc getDataDir(): string =
|
||||||
|
## Returns the data directory of the current user for applications.
|
||||||
|
# follows std/os.getCacheDir
|
||||||
|
# which in turn follows https://crates.io/crates/platform-dirs
|
||||||
|
result =
|
||||||
|
when defined(windows):
|
||||||
|
getEnv("LOCALAPPDATA")
|
||||||
|
elif defined(osx):
|
||||||
|
getEnv("XDG_DATA_HOME", getEnv("HOME") / "Library/Application Support")
|
||||||
|
else:
|
||||||
|
getEnv("XDG_DATA_HOME", getEnv("HOME") / ".local/share")
|
||||||
|
|
||||||
|
result.normalizePathEnd(false)
|
||||||
|
|
||||||
|
proc getOizysLogPath(): string =
|
||||||
|
let dataDir = getDataDir()
|
||||||
|
createDir(dataDir / "oizys")
|
||||||
|
result = dataDir / "oizys" / "oizys.log"
|
||||||
|
|
||||||
|
|
||||||
|
setLogFilter(lvlAll)
|
||||||
|
|
||||||
|
proc setupLoggers*(debug: bool) =
|
||||||
|
let logLevel =
|
||||||
|
if not debug: lvlInfo
|
||||||
|
else: lvlAll
|
||||||
|
addHandler(
|
||||||
|
newFancyConsoleLogger(
|
||||||
|
fmtPrefix = $bb"[b magenta]oizys",
|
||||||
|
levelThreshold = logLevel
|
||||||
|
)
|
||||||
|
)
|
||||||
|
addHandler(
|
||||||
|
newRollingFileLogger(
|
||||||
|
getOizysLogPath(),
|
||||||
|
mode = fmAppend,
|
||||||
|
fmtStr = "$datetime | $levelid:"
|
||||||
|
)
|
||||||
|
)
|
Loading…
Reference in a new issue