https://github.com/brandonc/go-log
https://github.com/brandonc/go-log
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/brandonc/go-log
- Owner: brandonc
- License: mit
- Created: 2023-01-20T14:08:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-21T03:13:09.000Z (over 2 years ago)
- Last Synced: 2024-12-28T16:26:26.749Z (5 months ago)
- Language: Go
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# go-log
A simple logging library in go.
### Example Usage
```go
package mainimport (
"errors""github.com/brandonc/go-log"
)func main() {
// Reads the LOG environment variable to determine log level
logger := log.NewLoggerFromEnv()// This version would log errors to stderr
// logger := log.DefaultLoggerlogger.Trace("This is a trace message")
logger.Debug("This is a debug message")
logger.Info("This is an info message")
logger.Warn("This is a warning")
logger.Errorf("This is an error: %v", errors.New("some error"))
}
```### Example Output:
```
$ go run main.go
2023-01-20T06:39:30.116-07:00 [ERROR] This is an error: some error
``````
$ LOG=debug go run main.go
2023-01-20T06:41:06.112-07:00 [DEBUG] This is a debug message
2023-01-20T06:41:06.112-07:00 [INFO] This is an info message
2023-01-20T06:41:06.112-07:00 [WARN] This is a warning
2023-01-20T06:41:06.112-07:00 [ERROR] This is an error: some error
```