noplog

package
v0.0.0-...-f32f910 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: MIT Imports: 1 Imported by: 4

README

Noplog

A noop logger for capturing internal logging.

This functionality exists because some third party packages (looking at you, grpc) have internal logging that may interfere with primary application logging. The noplog can be passed to those libraries, allowing you to stifle those log messages in favor of your application logs.

Usage:

// Initialize the package.
func init() {
	// Set the random seed to something different each time.
    // This is very common in init
	rand.Seed(time.Now().Unix())

	// Stop the grpc verbose logging
	grpclog.SetLogger(noplog.New())
}

Note that the init() function is run to initialize the package after all variable definitions have been set but before the main function is executed.

Documentation

Overview

Package noplog implements a noop logger with a null writer.

The writer implements the io.Write interface but does not do anything. All logging function definitions are empty noops.

Common use:

// Initialize the package.
func init() {
    // Set the random seed to something different each time.
    // This is very common in init
    rand.Seed(time.Now().Unix())

    // Stop the grpc verbose logging
    grpclog.SetLogger(noplog.New())
}

This functionality exists because some third party packages (looking at you, grpc) have internal logging that may interfere with primary application logging. The noplog can be passed to those libraries, allowing you to stifle those log messages in favor of your application logs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NopLogger

type NopLogger struct {
	*log.Logger
}

NopLogger is a noop logger for passing to grpclog to minimize spew.

func New

func New() *NopLogger

New returns a NopLogger that sets the log module to write to a null writer, thereby ensuring that logging is a noop for any package that uses the logger.

func (*NopLogger) Fatal

func (l *NopLogger) Fatal(args ...interface{})

Fatal is a noop

func (*NopLogger) Fatalf

func (l *NopLogger) Fatalf(format string, args ...interface{})

Fatalf is a noop

func (*NopLogger) Fatalln

func (l *NopLogger) Fatalln(args ...interface{})

Fatalln is a noop

func (*NopLogger) Print

func (l *NopLogger) Print(args ...interface{})

Print is a noop

func (*NopLogger) Printf

func (l *NopLogger) Printf(format string, args ...interface{})

Printf is a noop

func (*NopLogger) Println

func (l *NopLogger) Println(v ...interface{})

Println is a noop

type NullWriter

type NullWriter int

NullWriter implements the io.Write interface but doesn't do anything.

func (NullWriter) Write

func (NullWriter) Write([]byte) (int, error)

Write implements the io.Write interface but is a noop.

Jump to

Keyboard shortcuts

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