@@ -3,6 +3,9 @@ package logger
3
3
import (
4
4
"fmt"
5
5
"os"
6
+ "runtime"
7
+ "strings"
8
+ "time"
6
9
)
7
10
8
11
type LogWriter struct {
@@ -26,9 +29,37 @@ func NewLogWriter() *LogWriter {
26
29
27
30
func (lw * LogWriter ) Write (p []byte ) (n int , err error ) {
28
31
if lw .Level == DebugLevel {
29
- fmt .Fprintf (os .Stdout , "[DEBUG] %s" , string (p ))
30
- } else {
31
- fmt .Fprintf (os .Stdout , "[INFO] %s" , string (p ))
32
+
33
+ buf := make ([]byte , 1024 )
34
+ runtime .Stack (buf , false )
35
+
36
+ debugMessage := fmt .Sprintf (
37
+ "[DEBUG] %s\n Timestamp: %s\n Stack Trace:\n %s\n " ,
38
+ string (p ),
39
+ time .Now ().Format (time .RFC3339 ),
40
+ string (buf ),
41
+ )
42
+ fmt .Fprint (os .Stdout , debugMessage )
43
+ return len (debugMessage ), nil
32
44
}
45
+
46
+ message := extractRelevantInfo (string (p ))
47
+ fmt .Fprintf (os .Stdout , "[INFO] %s" , message )
33
48
return len (p ), nil
34
49
}
50
+
51
+ func extractRelevantInfo (message string ) string {
52
+ lines := strings .Split (message , "\n " ) // Split message into lines
53
+ var filteredLines []string
54
+
55
+ for _ , line := range lines {
56
+ // Exclude unnecessary debug/error details
57
+ if strings .Contains (line , "[FAILED] Expected" ) ||
58
+ strings .Contains (line , "In [It] at:" ) {
59
+ continue // Skip these lines
60
+ }
61
+ filteredLines = append (filteredLines , line )
62
+ }
63
+
64
+ return strings .Join (filteredLines , "\n " ) // Reconstruct filtered message
65
+ }
0 commit comments