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.
go get github.com/gowizzard/proto
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
.
Thanks to JetBrains for supporting me with this and other open source projects.