Files
conquest/src/server/core/logger.nim

33 lines
1.1 KiB
Nim
Raw Normal View History

2025-08-21 15:08:52 +02:00
import times, strformat, strutils
import std/[dirs, paths]
import ../../common/[types, profile]
proc makeAgentLogDirectory*(cq: Conquest, agentId: string): bool =
try:
let cqDir = cq.profile.getString("conquest_directory")
createDir(cast[Path](fmt"{cqDir}/data/logs/{agentId}"))
return true
except OSError:
return false
proc log*(cq: Conquest, logEntry: string) =
let
date = now().format("dd-MM-yyyy")
cqDir = cq.profile.getString("conquest_directory")
2025-08-21 15:08:52 +02:00
agentLogPath = fmt"{cqDir}/data/logs/{cq.interactAgent.agentId}/{date}.session.log"
# Write log entry to file
let file = open(agentLogPath, fmAppend)
2025-08-21 15:08:52 +02:00
file.writeLine(fmt"{logEntry}")
file.flushFile()
2025-08-21 15:08:52 +02:00
proc extractStrings*(args: string): string =
if not args.startsWith("("):
return args
# Remove styling arguments, such as fgRed, styleBright, resetStyle, etc. by extracting only arguments that are quoted
var message: string
for str in args[1..^2].split(", "):
if str.startsWith("\""):
message &= str
2025-08-21 15:08:52 +02:00
return message.replace("\"", "")