logAdapter

package module
v0.0.0-...-8ccbadd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2019 License: MIT Imports: 5 Imported by: 0

README

LogAdapter

This repo is a adapter to the package 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

package main

import (
    "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())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogAdapter

func LogAdapter(m l.MsgType, o l.OutType, config map[string]interface{}, msg ...interface{})

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL