Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gowizzard/proto
An library to log from golang to file or command line.
https://github.com/gowizzard/proto
command-line filesystem go golang golang-library logging logs protocol
Last synced: about 1 month ago
JSON representation
An library to log from golang to file or command line.
- Host: GitHub
- URL: https://github.com/gowizzard/proto
- Owner: gowizzard
- License: mit
- Created: 2022-08-25T13:17:35.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-27T09:54:38.000Z (over 2 years ago)
- Last Synced: 2024-10-29T20:29:49.795Z (3 months ago)
- Topics: command-line, filesystem, go, golang, golang-library, logging, logs, protocol
- Language: Go
- Homepage:
- Size: 64.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# proto
[![GitHub go.mod Go version of a Go module](https://img.shields.io/github/go-mod/go-version/gowizzard/proto.svg)](https://golang.org/) [![Go](https://github.com/gowizzard/proto/actions/workflows/go.yml/badge.svg)](https://github.com/gowizzard/proto/actions/workflows/go.yml) [![CodeQL](https://github.com/gowizzard/proto/actions/workflows/codeql.yml/badge.svg)](https://github.com/gowizzard/proto/actions/workflows/codeql.yml) [![CompVer](https://github.com/gowizzard/proto/actions/workflows/compver.yml/badge.svg)](https://github.com/gowizzard/proto/actions/workflows/compver.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/gowizzard/proto)](https://goreportcard.com/report/github.com/gowizzard/proto) [![Go Reference](https://pkg.go.dev/badge/github.com/gowizzard/proto.svg)](https://pkg.go.dev/github.com/gowizzard/proto) [![GitHub issues](https://img.shields.io/github/issues/gowizzard/proto)](https://github.com/gowizzard/proto/issues) [![GitHub forks](https://img.shields.io/github/forks/gowizzard/proto)](https://github.com/gowizzard/proto/network) [![GitHub stars](https://img.shields.io/github/stars/gowizzard/proto)](https://github.com/gowizzard/proto/stargazers) [![GitHub license](https://img.shields.io/github/license/gowizzard/proto)](https://github.com/gowizzard/proto/blob/master/LICENSE)
The name proto comes from the German word protokollieren `/protokolliéren/`. Accordingly, the whole thing has nothing to do with creating prototypes, but only logging. Since of course also with pleasure for prototypes.
## Install
```console
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](https://github.com/gowizzard/proto/issues) if desired.
Here you can find an example how to use the library:
```go
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:
```console
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:
```go
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](https://github.com/JetBrains) for supporting me with this and other [open source projects](https://www.jetbrains.com/community/opensource/#support).