Skip to content

Commit

Permalink
Merge pull request #1 from japerry911/japerry911/new/v0.1.0
Browse files Browse the repository at this point in the history
kestra: release first version that includes only logging for v0.1.0
  • Loading branch information
japerry911 authored Oct 19, 2024
2 parents 44d04bd + 0e6bd1f commit 5cc68d6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# kestra-go
Kestra GoLang module.

This is the unofficial Kestra GoLang support module.

Currently this module's functionality includes allowing users to log messages with either TRACE, DEBUG, INFO, WARNING, ERROR, or CRTIICAL level and it'll log in a format that is understandable by your Kestra instance.

The roadmap for this package to add better documentation and unit tests in the near future, and also adding the ability to send outputs to your Kestra instance.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/japerry911/kestra-go

go 1.23.0
70 changes: 70 additions & 0 deletions kestra.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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) Warning(message string) {
k.logMessage("WARNING", message)
}

func (k *KestraLogger) Error(message string) {
k.logMessage("ERROR", message)
}

func (k *KestraLogger) Critical(message string) {
k.logMessage("CRITICAL", message)
}

0 comments on commit 5cc68d6

Please sign in to comment.