In Egyptian Mythology, Thoth was the Egyptian ibis-headed god of knowledge, magic and wisdom.
Thoth is an error logger for golang. It helps log errors to a log file so you can go back to find how why and when something breaks in production.
You can install Thoth by running:
go get github.com/ichtrojan/thoth
Thoth supports logging to two filetypes:
- log
- json
...
file, err := thoth.Init("log")
if err != nil {
log.Fatal(err)
}
...
...
json, err := thoth.Init("json")
if err != nil {
log.Fatal(err)
}
...
Regardless of the variable assigned to a Thoth Init
function and log format; errors can be logged using the Log
function.
Logging errors from packages
...
if err != nil {
file.Log(err)
}
...
Logging custom errors based on a given condition
...
isBroke := true
if isBroke {
file.Log(errors.New("something went wrong"))
}
...
Logging errors from packages
...
if err != nil {
json.Log(err)
}
...
Logging custom errors based on a given condition
...
high := true
if high {
json.Log(errors.New("highest in the room"))
}
...
You can serve a dashboard to view your logs in realtime using the Serve
function. Depending on the filetype specified in the Init
function, it will serve the content of your log file.
file.Serve({dashboard route}, {dashboard password})
...
if err := file.Serve("/logs", "12345"); err != nil {
log.Fatal(err)
}
if err := http.ListenAndServe(":8000", nil); err != nil {
file.Log(err)
}
...
The snippet above will serve your realtime log dashboard on port 8000
and can be visited on /logs
route.
You can also check the example directory to see a sample usage.
NOTE The realtime dashboard for
json
is currently on beta, it can be used but still looks experimental.
Contributions are welcome to this project to further improve it to suit the general public need. I hope you enjoy the simplicity of Thoth and cannot wait to see the wonderful project you build with it.