Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rodkranz/xlog
https://github.com/rodkranz/xlog
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/rodkranz/xlog
- Owner: rodkranz
- Created: 2017-10-26T16:12:47.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-04T20:38:29.000Z (over 6 years ago)
- Last Synced: 2024-11-07T22:42:23.780Z (about 2 months ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# XLOG
Simple usage:
----
# **Console**:Write log at console with colors
#### Config Options:
| Variables | Types | Description | Options |
|----------------|--------------|--------------------------------------------|---------
| Level | LEVEL | Define level of log (Default: **0**) | TRACE, INFO, WARN, ERROR, FATAL
| BufferSize | int64 | Buffer size (Default: **0**) | In64 size
| Writer | io.Writer | Where will write log (Default: **Stdout**) | Any io.writer implementation
| ValuesDefault| interface | Define default values for output | array of interface{}|#### Example:
```go
err := xlog.New(xlog.CONSOLE, xlog.ConsoleConfig{})
if err != nil {
fmt.Printf("Fail to create new logger: %v\n", err)
os.Exit(1)
}now := time.Now().Format("02 Jan 06 15:04")
xlog.Info("type", "Info", "Transponder", now, "version", xlog.Version())
xlog.Trace("type", "Trace", "Transponder", now, "version", xlog.Version())
```#### Output:
```bash
[ INFO] service=XPTO type=Info Transponder="25 Oct 17 18:11" version=0.0.1
[TRACE] service=XPTO type=Trace Transponder="25 Oct 17 18:11" version=0.0.1
```----
# **Json Format**:#### Config Options:
| Variables | Types | Description | Options |
|----------------|--------------|--------------------------------------------|---------
| Level | LEVEL | Define level of log (Default: **0**) | TRACE, INFO, WARN, ERROR, FATAL
| BufferSize | int64 | Buffer size (Default: **0**) | In64 size
| Writer | io.Writer | Where will write log (Default: **Stdout**) | Any io.writer implementation
| ValuesDefault| interface | Define default values for output | array of interface{}|#### Example:
```go
err := xlog.New(xlog.JSONFormat, xlog.JsonFormatConfig{
Writer: os.Stdout,
Level: xlog.TRACE,
ValuesDefault: []interface{}{"service", "XPTO"},
})
if err != nil {
fmt.Printf("Fail to create new logger: %v\n", err)
os.Exit(1)
}now := time.Now().Format("02 Jan 06 15:04")
xlog.Info("type", "Info", "Transponder", now, "version", xlog.Version())
xlog.Trace("type", "Trace", "Transponder", now, "version", xlog.Version()
```#### Output:
```json
{"service": "XPTO", "Transponder":"25 Oct 17 18:13","type":"Info","version":"0.0.1"}
{"service": "XPTO", "Transponder":"25 Oct 17 18:13","type":"Trace","version":"0.0.1"}
```---