Skip to content
This repository was archived by the owner on May 24, 2025. It is now read-only.

Commit 7ab2450

Browse files
authored
Merge pull request #2 from Bobonium/main
add json logging
2 parents 361bada + 181a87e commit 7ab2450

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cmd/main.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,25 @@ func handleEvent(pod *v1.Pod, clientset *kubernetes.Clientset) {
105105
if containerStatus.Ready {
106106
podlist := GetPodsByLabel(clientset, namespace, dovecotDirectorLabels)
107107

108-
for _, dovecotPod := range podlist.Items {
108+
for _, dovecotDirectorPod := range podlist.Items {
109+
time := time.Now()
110+
logLevel := "info"
111+
logMessage := "success"
112+
formattedTime := time.Format("2006-01-02 15:04:05 MST")
113+
109114
err := ExecuteCommand(
110115
"doveadm reload",
111-
dovecotPod.ObjectMeta.Name,
116+
dovecotDirectorPod.ObjectMeta.Name,
112117
namespace,
113118
clientset)
119+
114120
if err != nil {
115-
fmt.Println(err.Error())
121+
logLevel = "error"
122+
logMessage = err.Error()
116123
}
124+
125+
log := fmt.Sprintf("{ \"level\": \"%s\", \"timestamp\": \"%s\", \"pod\": \"%s\", \"command\": \"doveadm reload\", \"message\": \"%s\" }", logLevel, formattedTime, dovecotDirectorPod.ObjectMeta.Name, logMessage)
126+
fmt.Println(log)
117127
}
118128
}
119129
}

0 commit comments

Comments
 (0)