ichtrojan / Thoth
Programming Languages
Projects that are alternatives of or similar to Thoth
Thoth
What is Thoth?
In Egyptian Mythology, Thoth was the Egyptian ibis-headed god of knowledge, magic and wisdom.
In this Context
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.
Installation
You can install Thoth by running:
go get github.com/ichtrojan/thoth
Usage
Thoth supports logging to two filetypes:
- log
- json
Step one - Initiate Thoth
log
Thoth Initiation for ...
file, err := thoth.Init("log")
if err != nil {
log.Fatal(err)
}
...
json
Thoth Initiation for ...
json, err := thoth.Init("json")
if err != nil {
log.Fatal(err)
}
...
Step two - Log errors
Regardless of the variable assigned to a Thoth Init
function and log format; errors can be logged using the Log
function.
log
Thoth Initiation for 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"))
}
...
json
Thoth Initiation for 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"))
}
...
Step three - Serve real-time logs dashboard
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.
Usage format
file.Serve({dashboard route}, {dashboard password})
log
Thoth serve for ...
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.
Contributors
Conclusion
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.