thoth

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2020 License: MIT Imports: 11 Imported by: 10

README

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
Thoth Initiation for log
...
file, err := thoth.Init("log")

if err != nil {
    log.Fatal(err)
}
...
Thoth Initiation for json
...
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.

Thoth Initiation for log

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"))
}
...
Thoth Initiation for json

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})
Thoth serve for log
...
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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

func Init

func Init(filetype string) (Config, error)

func (Config) Log

func (config Config) Log(error error)

func (Config) Serve added in v1.2.0

func (config Config) Serve(endpoint string, key string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL