Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arxdsilva/logadapter
log adapter to nuveo/log
https://github.com/arxdsilva/logadapter
adapter golang golang-lib library
Last synced: 5 days ago
JSON representation
log adapter to nuveo/log
- Host: GitHub
- URL: https://github.com/arxdsilva/logadapter
- Owner: arxdsilva
- License: mit
- Created: 2019-04-30T17:02:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-04-30T18:59:53.000Z (over 5 years ago)
- Last Synced: 2024-10-12T09:20:06.467Z (about 1 month ago)
- Topics: adapter, golang, golang-lib, library
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## LogAdapter
This repo is a adapter to the package [nuveo/log](github.com/nuveo/log) that uses Golang's standard `log` instead of `fmt` package to write into stdout. This is useful for testing if a application logged something by setting the log to a buffer.
## [Testing logs with this adapter](https://stackoverflow.com/questions/44119951/how-to-check-a-log-output-in-go-test)
```go
package mainimport (
"bytes"
"fmt"
"io"
"os"
"testing"
l "log""github.com/nuveo/log"
la "github.com/arxdsilva/logAdapter"
)func readByte() {
// force an error
err := io.EOF
if err != nil {
log.Println("Couldn't read first byte")
}
}func TestReadByte(t *testing.T) {
// remove std adapter
// this prevents double logging
log.RemoveAdapter("stdout")
log.AddAdapter("adapter", log.AdapterPod{Adapter:la.LogAdapter, Config: nil})
var buf bytes.Buffer
l.SetOutput(&buf)
defer func() {
l.SetOutput(os.Stderr)
}()
readByte()
// do something with the logs
t.Log(buf.String())
}
```