MCPcopy
hub / github.com/SurgeDM/Surge / Debug

Function Debug

internal/utils/debug.go:38–61  ·  view source on GitHub ↗

Debug writes a message to debug.log file in the configured directory

(format string, args ...any)

Source from the content-addressed store, hash-verified

36
37// Debug writes a message to debug.log file in the configured directory
38func Debug(format string, args ...any) {
39 // Internal fast path check without lock
40 val := logsDir.Load()
41 if val == nil {
42 return
43 }
44 dir := val.(string)
45 if dir == "" {
46 return
47 }
48
49 // Calculate timestamp only if we are actually logging
50 timestamp := time.Now().Format("2006-01-02 15:04:05")
51
52 // Ensure file is open (still needs once, but fast after first time)
53 debugOnce.Do(func() {
54 _ = os.MkdirAll(dir, 0o755)
55 debugFile, _ = os.Create(filepath.Join(dir, fmt.Sprintf("debug-%s.log", time.Now().Format("20060102-150405"))))
56 })
57
58 if debugFile != nil {
59 _, _ = fmt.Fprintf(debugFile, "[%s] %s\n", timestamp, fmt.Sprintf(format, args...))
60 }
61}
62
63// CleanupLogs removes old log files, keeping only the most recent retentionCount files
64func CleanupLogs(retentionCount int) {

Callers 15

TestDebug_CreatesLogFileFunction · 0.92
TestDebug_FormatsMessageFunction · 0.92
updateCategoryManagerMethod · 0.92
UpdateMethod · 0.92
startDownloadMethod · 0.92
updateSettingsMethod · 0.92
broadcastLoopMethod · 0.92

Calls

no outgoing calls