stdlogtoapex

package module
v0.0.0-...-4ac25d2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2018 License: BSD-3-Clause Imports: 2 Imported by: 0

README

stdlogtoapex

A small library to bridge Go's log package to github.com/apex/log.

Redirecting standard log messages to apex log.

stdlogtoapex provides Writer type that implements the io.Writer interface and can be passed to the standard library log.SetOutput function. When this is done, all subsequent calls to the log packages output functions will send their output to via this Writer, and it will, in turn, log that output via Apex log's default handler.

Example

package main

import (
    "log"
    ]
    "github.com/avct/stdlogtoapex"
    alog "github.com/apex/log"
    "github.com/apex/log/handlers/cli"
)

func main() {
    handler := cli.Default
	alog.SetHandler(handler)
	writer := stdlogtoapex.NewWriter()
    
    // From this point all output from the standard library log package will be ouptup via the Writer
	log.SetOutput(writer)
	log.Print("Hello!")
}

Caveat

This package will not capture logging sent via the "log/syslog" package.

Documentation

Overview

stdlogtoapex is a package that provides an implementation of

/* io.Writer that can be used to redirect log output from the standard /* libraries log package via github.com/apex/log.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer is a struct that implements the io.Writer interface and can, therefore, be passed into log.SetOutput. Writer must always be constructed by called NewWriter.

func NewWriter

func NewWriter() *Writer

NewWriter creates a new Writer that can be passed to the SetOutput function in the log package from the standard library.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write implements the io.Writer interface for Writer. Log messages output via this method will have their date and time information stripped (apex log will have its own) .

Jump to

Keyboard shortcuts

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