gowizzard / proto

An library to log from golang to file or command line.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

proto

GitHub go.mod Go version of a Go module Go CodeQL CompVer Go Report Card Go Reference GitHub issues GitHub forks GitHub stars GitHub license

The name proto comes from the German word protokollieren /protokollieĢren/. Accordingly, the whole thing has nothing to do with creating prototypes, but only logging. Since of course also with pleasure for prototypes.

Install

go get github.com/gowizzard/proto

How to use?

The library should help you to make logging easier for the command line as well as file based. For example, you can add the file information to your error message, so that we can enter the exact file and line of the error. You can also add more attributes via a map.

The functionality is currently being expanded, so check back from time to time, or create an issue if desired.

Here you can find an example how to use the library:

c := proto.Config{
    Information:    true, 
    Convert: &map[string]string{
        "error": "purple",
    }, 
    Monthly:	    false,
    CommandLine:    false,
    File:           true,
    Path:           "/var/log/proto",
} 

err := c.Log("error", "this is the error message", map[string]any{})
if err != nil {
    log.Fatal(err)
}

In this example, we generate the configuration we need as it stores general information. Here you can store for example the path to the folder of the log files, or also whether a log in the command line or only file-based. Both and is also possible.

If you want to log file based, then we create in a specified path a folder per month and for each day a separate log file in this folder, so you always get the best overview of your logs.

Here you can find a sample log:

INFO[2022-08-26T11:51:30]  This is a informational message.	FILE=log_test.go:65

We color the log kinds so that you can differentiate them immediately, so error is shown as red and warning as yellow. Everything else is displayed in cyan.

If you want to map to other kinds of colors, you can store them in the convert map. Please note that the default values will be overwritten. These look like this:

map[string]string{
    "default": "cyan",
    "error":   "red",
    "warning": "yellow",
}

You can use the following colors for your mapping: red, green, yellow, blue, purple & cyan.

Special thanks

Thanks to JetBrains for supporting me with this and other open source projects.

About

An library to log from golang to file or command line.

License:MIT License


Languages

Language:Go 97.9%Language:Makefile 2.1%