-
Notifications
You must be signed in to change notification settings - Fork 0
/
kestra.go
66 lines (51 loc) · 1.15 KB
/
kestra.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package kestra
import (
"encoding/json"
"log"
"os"
"time"
)
type Kestra struct {
Logger *KestraLogger
}
func NewKestra() *Kestra {
return &Kestra{}
}
type KestraLogger struct{}
type LogEntry struct {
Level string `json:"level"`
Message string `json:"message"`
}
type LogOutput struct {
Logs []LogEntry `json:"logs"`
}
func (k *KestraLogger) logMessage(level, message string) {
timestamp := time.Now().Format(time.RFC3339Nano)
logEntry := LogEntry{
Level: level,
Message: timestamp + " - " + message,
}
logOutput := LogOutput{
Logs: []LogEntry{logEntry},
}
jsonOutput, err := json.Marshal(logOutput)
if err != nil {
log.Fatalf("Error marshalling log output: %v", err)
}
os.Stdout.Write([]byte("::" + string(jsonOutput) + "::\n"))
}
func (k *KestraLogger) Trace(message string) {
k.logMessage("TRACE", message)
}
func (k *KestraLogger) Debug(message string) {
k.logMessage("DEBUG", message)
}
func (k *KestraLogger) Info(message string) {
k.logMessage("INFO", message)
}
func (k *KestraLogger) Warn(message string) {
k.logMessage("WARN", message)
}
func (k *KestraLogger) Error(message string) {
k.logMessage("ERROR", message)
}