https://github.com/hyperjumptech/hyperlog
A logging framework for golang programming language
https://github.com/hyperjumptech/hyperlog
Last synced: about 1 year ago
JSON representation
A logging framework for golang programming language
- Host: GitHub
- URL: https://github.com/hyperjumptech/hyperlog
- Owner: hyperjumptech
- License: gpl-3.0
- Created: 2024-08-07T07:01:50.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-08T04:52:10.000Z (almost 2 years ago)
- Last Synced: 2025-01-20T06:33:01.454Z (over 1 year ago)
- Language: Go
- Size: 24.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Hyperlog
Simple logging framework that works.
## Importing
```bash
$ go get github.com/hyperjumptech/hyperlog
```
## Features
It enable the following capabilities:
- Log Level
- JSON Log Output
- Log Hook and triggers on any level
- Shutdown Hook
- Log to any implementation io.Writer
- Writer implementation to write log for rolling based on time
- Writer implementation to write log for rolling based on size
- Log writer with "Attribute" (a.k.a "Field")
- Http middleware to log Request/Response
## Using hyperlog
### Preparation
Just import the library, as simple as that.
```go
import "github.com/hyperjumptech/hyperlog"
```
### Configure
### Logging
The following can be use for logging straight away...
```go
func Trace(str ...interface{})
func Debug(str ...interface{})
func Info(str ...interface{})
func Warn(str ...interface{})
func Error(str ...interface{})
func Fatal(str ...interface{})
func Tracef(format string, ...interface{})
func Debugf(format string, arg ...interface{})
func Infof(format string, arg ...interface{})
func Warnf(format string, arg ...interface{})
func Errorf(format string, arg ...interface{})
func Fatalf(format string, arg ...interface{})
```
So you can directly use them like ...
```go
import "github.com/hyperjumptech/hyperlog"
func DoSomething() {
hyperlog.Warn("This is a warning")
}
func DoSomethingAgain() {
hyperlog.Warnf("This is a %s", "warning")
}
```
Or you can create a logger using `WithAttribute` to add some specific attribute.
```go
import "github.com/hyperjumptech/hyperlog"
func LogIt() {
log1 := hyperlog.WithAttribute("key", "Value One")
log2 := hyperlog.WithAttribute("moreKey", "More Value")
log3 := log2.WithAttribute("anotherKey", "More Value")
log1.Info("Hello One")
log2.Info("More Hello")
log3.Info("Another log")
}
```
which will log something like the following (in plain format)
```text
[INFO] 2024-07-21T10:10:00 Hello One key="Value One"
[INFO] 2024-07-21T10:10:00 More Hello moreKey="More Value"
[INFO] 2024-07-21T10:10:00 Another log moreKey="More Value" anotherKey="More Value"
```
### Changing Output Format
You can generate log in either "JSON" or "Plain" format.
```go
import "github.com/hyperjumptech/hyperlog"
func init() {
OutFormat = JSONFormat // this will produce log JSON format
... or ...
OutFormat = PlainFormat // this will produce log in Plain Text format
}
```
so, a call like this ...
```go
hyperlog.Error("an error has occurred")
```
will log ...
JSON
```text
{"lvl"="error","time":"2024-07-21T10:10:00","msg":an error has occurred"}
```
or Plain Text
```text
[error] 2024-07-21T10:10:00 an error has occurred
```
### Changing Writer (output target)
You can change the logging target like following.
```go
import "github.com/hyperjumptech/hyperlog"
func init() {
hyperlog.SetWriter(os.StdOut)
}
```
or
```go
import "github.com/hyperjumptech/hyperlog"
func init() {
hyperlog.SetWriter(os.StdErr)
}
```
or
```go
import "github.com/hyperjumptech/hyperlog"
type CustomWriter struct {}
func (c *CustomWriter) Write(b []byte) (written int, err error) {
// some io.Writer() logic.
}
func init() {
hyperlog.SetWriter(&CustomWriter{})
}
```
This you can set the log target as specified.
### Hooks
__More documentation will be added soon__
### File Based Writer
#### Rolling Log File based on Time
__More documentation will be added soon__
#### Rolling Log File based on file size
__More documentation will be added soon__