-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from japerry911/japerry911/new/v0.1.0
kestra: release first version that includes only logging for v0.1.0
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/japerry911/kestra-go | ||
|
||
go 1.23.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |