Improved logging format.

This commit is contained in:
Jakob Friedl
2025-08-21 15:08:52 +02:00
parent f69adc53a2
commit c9df7aba64
18 changed files with 91 additions and 115 deletions

View File

@@ -1,4 +1,4 @@
import terminal, times, strformat, strutils
import times, strformat, strutils
import std/[dirs, paths]
import ../../common/[types, profile]
@@ -11,21 +11,17 @@ proc makeAgentLogDirectory*(cq: Conquest, agentId: string): bool =
return false
proc log*(cq: Conquest, logEntry: string) =
if cq.interactAgent == nil:
return
let
date = now().format("dd-MM-yyyy")
timestamp = now().format("dd-MM-yyyy HH:mm:ss")
cqDir = cq.profile.getString("conquest_directory")
agentLogPath = fmt"{cqDir}/data/logs/{cq.interactAgent.agentId}/{date}.log"
agentLogPath = fmt"{cqDir}/data/logs/{cq.interactAgent.agentId}/{date}.session.log"
# Write log entry to file
let file = open(agentLogPath, fmAppend)
file.writeLine(fmt"[{timestamp}] {logEntry}")
file.writeLine(fmt"{logEntry}")
file.flushFile()
proc extractStrings(args: string): string =
proc extractStrings*(args: string): string =
if not args.startsWith("("):
return args
@@ -34,24 +30,4 @@ proc extractStrings(args: string): string =
for str in args[1..^2].split(", "):
if str.startsWith("\""):
message &= str
return message.replace("\"", "")
template info*(cq: Conquest, args: varargs[untyped]) =
cq.writeLine(fgBlack, styleBright, "[*] ", resetStyle, args)
cq.log("[*] " & extractStrings($(args)))
template error*(cq: Conquest, args: varargs[untyped]) =
cq.writeLine(fgRed, styleBright, "[-] ", resetStyle, args)
cq.log("[-] " & extractStrings($(args)))
template warn*(cq: Conquest, args: varargs[untyped]) =
cq.writeLine(fgYellow, "[!] ", resetStyle, args)
cq.log("[!] " & extractStrings($(args)))
template success*(cq: Conquest, args: varargs[untyped]) =
cq.writeLine(fgGreen, "[+] ", resetStyle, args)
cq.log("[+] " & extractStrings($(args)))
template output*(cq: Conquest, args: varargs[untyped]) =
cq.writeLine(args)
cq.log("[>] " & extractStrings($(args)))
return message.replace("\"", "")