Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aphistic/gomol-json
A gomol logger to write JSON over TCP or UDP.
https://github.com/aphistic/gomol-json
gomol
Last synced: about 2 months ago
JSON representation
A gomol logger to write JSON over TCP or UDP.
- Host: GitHub
- URL: https://github.com/aphistic/gomol-json
- Owner: aphistic
- License: mit
- Created: 2016-08-10T14:47:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-16T16:03:25.000Z (over 6 years ago)
- Last Synced: 2024-10-12T16:19:58.745Z (3 months ago)
- Topics: gomol
- Language: Go
- Size: 30.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
gomol-json
============[![GoDoc](https://godoc.org/github.com/aphistic/gomol-json?status.svg)](https://godoc.org/github.com/aphistic/gomol-json)
[![Build Status](https://img.shields.io/travis/aphistic/gomol-json.svg)](https://travis-ci.org/aphistic/gomol-json)
[![Code Coverage](https://img.shields.io/codecov/c/github/aphistic/gomol-json.svg)](http://codecov.io/github/aphistic/gomol-json?branch=master)gomol-json is a logger for [gomol](https://github.com/aphistic/gomol) to support logging JSON over a network.
Installation
============To install gomol-json, simply `go get` it and import it into your project:
go get github.com/aphistic/gomol-json
...
import "github.com/aphistic/gomol-json"Examples
========For brevity a lot of error checking has been omitted, be sure you do your checks!
This is a super basic example of adding a JSON logger to gomol and then logging a few messages:
```go
package mainimport (
"github.com/aphistic/gomol"
)// Create a new JSON logger, add it to gomol and log a few messages
func Example() {
// Add a JSON Logger
jsonCfg := NewJSONLoggerConfig("tcp://10.10.10.10:1234")
jsonLogger, _ := NewJSONLogger(jsonCfg)
gomol.AddLogger(jsonLogger)// Set some global attrs that will be added to all
// messages automatically
gomol.SetAttr("facility", "gomol.example")
gomol.SetAttr("another_attr", 1234)// Initialize the loggers
gomol.InitLoggers()
defer gomol.ShutdownLoggers()// Log some debug messages with message-level attrs
// that will be sent only with that message
for idx := 1; idx <= 10; idx++ {
gomol.Dbgm(
gomol.NewAttrs().
SetAttr("msg_attr1", 4321),
"Test message %v", idx)
}
}```