Z3
 
Loading...
Searching...
No Matches
log.go
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation 2025
2// Z3 Go API: Logging functionality
3
4package z3
5
6/*
7#include "z3.h"
8#include <stdlib.h>
9*/
10import "C"
11import (
12 "sync"
13 "unsafe"
14)
15
16var (
17 logMutex sync.Mutex
18 isLogOpen bool
19)
20
21// OpenLog opens an interaction log file
22// Returns true if successful, false otherwise
23func OpenLog(filename string) bool {
24 logMutex.Lock()
25 defer logMutex.Unlock()
26
27 cFilename := C.CString(filename)
28 defer C.free(unsafe.Pointer(cFilename))
29
30 result := C.Z3_open_log(cFilename)
31 if bool(result) {
32 isLogOpen = true
33 return true
34 }
35 return false
36}
37
38// CloseLog closes the interaction log
39func CloseLog() {
40 logMutex.Lock()
41 defer logMutex.Unlock()
42
43 C.Z3_close_log()
44 isLogOpen = false
45}
46
47// EnableTrace enables trace messages for tag.
48func EnableTrace(tag string) {
49 logMutex.Lock()
50 defer logMutex.Unlock()
51
52 cTag := C.CString(tag)
53 defer C.free(unsafe.Pointer(cTag))
54 C.Z3_enable_trace(cTag)
55}
56
57// DisableTrace disables trace messages for tag.
58func DisableTrace(tag string) {
59 logMutex.Lock()
60 defer logMutex.Unlock()
61
62 cTag := C.CString(tag)
63 defer C.free(unsafe.Pointer(cTag))
64 C.Z3_disable_trace(cTag)
65}
66
67// AppendLog appends a user-provided string to the interaction log
68// Panics if the log is not open
69func AppendLog(s string) {
70 logMutex.Lock()
71 defer logMutex.Unlock()
72
73 if !isLogOpen {
74 panic("Log is not open")
75 }
76
77 cStr := C.CString(s)
78 defer C.free(unsafe.Pointer(cStr))
79 C.Z3_append_log(cStr)
80}
81
82// IsLogOpen returns true if the interaction log is open
83func IsLogOpen() bool {
84 logMutex.Lock()
85 defer logMutex.Unlock()
86 return isLogOpen
87}