netlog

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

README

netlog

GoDoc GitHub

Project Overview

Package netlog provides an implementation of go-hclog.Logger that sends messages over the network to a listener. Useful for debug logging in situations where os.Stdout/os.Stderr are not available.

Also implements colorized local logging helpers, e.g. netlog.Yellow("message", "key", "value", ...)

Getting Started

The netlog command can be installed by running:

➜ go install github.com/shoenig/netlog/cmds/netlog@latest

Example usage:

help
➜ netlog help
Subcommands for [listening]:
	listen           Listen for log events

Subcommands for [logging]:
	debug            Send debug message to listener
	error            Send error message to listener
	info             Send info message to listener
	trace            Send trace message to listener
	warn             Send warn message to listener
listen
➜ netlog listen
netlog: listening @ 127.0.0.1:9999
logging

For convenience, the netlog command can directly emit log messages to a listener.

➜ netlog info This is a message!

It supports sending trace, debug, info, warn, error messages.

API

The utility of the netlog package is that it implements HashiCorp's go-hclog.Logger interface, and can be used as a drop-in replacement in situations where terminal output is not available.

import "github.com/shoenig/netlog"

// ... 

log := netlog.New()
log.Info("this is a message")

Contributing

Contributions are welcome! Feel free to help make netlog better.

License

The github.com/shoenig/netlog module is open source under the BSD-3-Clause license.

Documentation

Index

Constants

View Source
const (
	HeaderLevel       = "X-NetLog-Level"
	HeaderName        = "X-NetLog-Name"
	HeaderContentType = "Content-Type"
	HeaderUserAgent   = "User-Agent"
)
View Source
const (
	DefaultUseTLS  = false
	DefaultAddress = "127.0.0.1"
	DefaultPort    = 9999
	DefaultName    = "default"
	DefaultTimeout = 1 * time.Second
	EnvAddress     = "NETLOG_ADDRESS"
	EnvPort        = "NETLOG_PORT"
)

Variables

This section is empty.

Functions

func Blue

func Blue(format string, args ...any)

func Cyan

func Cyan(format string, args ...any)

func Green

func Green(format string, args ...any)

func Purple

func Purple(format string, args ...any)

func Red

func Red(format string, args ...any)

func White

func White(format string, args ...any)

func Yellow

func Yellow(format string, args ...any)

Types

type Level

type Level = hclog.Level

type Log

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

func New

func New(name string, opts ...Option) *Log

func (*Log) Debug

func (l *Log) Debug(msg string, args ...interface{})

func (*Log) Error

func (l *Log) Error(msg string, args ...interface{})

func (*Log) GetLevel added in v0.3.1

func (l *Log) GetLevel() hclog.Level

func (*Log) ImpliedArgs

func (l *Log) ImpliedArgs() []interface{}

func (*Log) Info

func (l *Log) Info(msg string, args ...interface{})

func (*Log) IsDebug

func (l *Log) IsDebug() bool

func (*Log) IsError

func (l *Log) IsError() bool

func (*Log) IsInfo

func (l *Log) IsInfo() bool

func (*Log) IsTrace

func (l *Log) IsTrace() bool

func (*Log) IsWarn

func (l *Log) IsWarn() bool

func (*Log) Log

func (l *Log) Log(level hclog.Level, msg string, args ...interface{})

func (*Log) Name

func (l *Log) Name() string

func (*Log) Named

func (l *Log) Named(name string) hclog.Logger

func (*Log) ResetNamed

func (l *Log) ResetNamed(name string) hclog.Logger

func (*Log) SetLevel

func (l *Log) SetLevel(level hclog.Level)

func (*Log) StandardLogger

func (l *Log) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger

func (*Log) StandardWriter

func (l *Log) StandardWriter(opts *hclog.StandardLoggerOptions) io.Writer

func (*Log) Trace

func (l *Log) Trace(msg string, args ...interface{})

func (*Log) Warn

func (l *Log) Warn(msg string, args ...interface{})

func (*Log) With

func (l *Log) With(args ...interface{}) hclog.Logger

type Option

type Option func(*Log)

func WithAddress

func WithAddress(address string) Option

func WithBlue added in v0.3.2

func WithBlue() Option

func WithGreen added in v0.3.2

func WithGreen() Option

func WithName

func WithName(name string) Option

func WithPort

func WithPort(port int) Option

func WithPurple added in v0.3.2

func WithPurple() Option

func WithRed added in v0.3.2

func WithRed() Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

func WithYellow added in v0.3.2

func WithYellow() Option

Directories

Path Synopsis
cmds

Jump to

Keyboard shortcuts

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