Categorygithub.com/rkennedy/nblog
modulepackage
0.0.0-20240911141031-3abbf97003f0
Repository: https://github.com/rkennedy/nblog.git
Documentation: pkg.go.dev

# README

nblog

Go Reference

The nblog package provides a handler for the slo package that formats records in the style of NetBackup "legacy" logs:

time [pid] <sev> caller: message

Additional attributes will appear JSON-style after the message.

Usage

go get github.com/rkennedy/nblog
package main

import (
	"log/slog"
	"os"

	"github.com/rkennedy/nblog"
)

func main() {
	logger := slog.New(nblog.NewHandler(os.Stdout))
	logger.Info("message")
}

# Functions

Level returns a [LegacyOption] that will configure a handler to filter out messages with a level lower than the given level.
NewHandler creates a new [LegacyHandler].
NumericSeverity configures a handler to record the log level as a number instead of a text label.
ReplaceAttrs returns a [LegacyOption] that configures a handler to include the given [ReplaceAttrFunc] callback function while processing log attributes prior to being recorded.
TimestampFormat returns a [LegacyOption] that will configure a handler to use the given time format (à la [time.Time.Format]) for log timestamps at the start of each record.
Trace marks the start of a function and returns a [TraceStopper] that can be used to mark the end of the function.
UseFullCallerName returns a [LegacyOption] that will configure a handler to include or omit the package-name portion of the caller in log messages.

# Constants

Formats for use with [TimestampFormat].
severity level.
When formatting a message, the handler calls any [ReplaceAttrFunc] callbacks on any attributes associated with the message.
process ID.
message timestamp.
Formats for use with [TimestampFormat].

# Structs

LegacyHandler is an implementation of [slog.Handler] that mimics the format used by legacy NetBackup logging.

# Interfaces

TraceStopper is the interface returned by [Trace] to allow callers to stop the trace.

# Type aliases

LegacyOption is a function that applies options to a new [LegacyHandler].
ReplaceAttrFunc is the type of callback used with [ReplaceAttrs] to allow editing, replacing, or removing of attributes nefore a log record is recorded.