logging

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package logging provides structured logging functionality using Go's slog package. It supports both text and JSON output formats, configurable log levels, and context-aware logging for the scanorama application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, fields ...any)

Debug logs at debug level using the default logger.

func Error

func Error(msg string, fields ...any)

Error logs at error level using the default logger.

func ErrorDaemon

func ErrorDaemon(msg string, err error, fields ...any)

ErrorDaemon logs daemon-related errors using the default logger.

func ErrorDatabase

func ErrorDatabase(msg string, err error, fields ...any)

ErrorDatabase logs database-related errors using the default logger.

func ErrorDiscovery

func ErrorDiscovery(msg, network string, err error, fields ...any)

ErrorDiscovery logs discovery-related errors using the default logger.

func ErrorScan

func ErrorScan(msg, target string, err error, fields ...any)

ErrorScan logs scan-related errors using the default logger.

func Info

func Info(msg string, fields ...any)

Info logs at info level using the default logger.

func InfoDaemon

func InfoDaemon(msg string, fields ...any)

InfoDaemon logs daemon-related information using the default logger.

func InfoDatabase

func InfoDatabase(msg string, fields ...any)

InfoDatabase logs database-related information using the default logger.

func InfoDiscovery

func InfoDiscovery(msg, network string, fields ...any)

InfoDiscovery logs discovery-related information using the default logger.

func InfoScan

func InfoScan(msg, target string, fields ...any)

InfoScan logs scan-related information using the default logger.

func SetDefault

func SetDefault(logger *Logger)

SetDefault sets the default logger instance.

func Warn

func Warn(msg string, fields ...any)

Warn logs at warn level using the default logger.

Types

type Config

type Config struct {
	Level     LogLevel  `yaml:"level" json:"level"`
	Format    LogFormat `yaml:"format" json:"format"`
	Output    string    `yaml:"output" json:"output"`
	AddSource bool      `yaml:"add_source" json:"add_source"`
}

Config holds logging configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default logging configuration.

type LogFormat

type LogFormat string

LogFormat represents the available log formats.

const (
	FormatText LogFormat = "text"
	FormatJSON LogFormat = "json"
)

type LogLevel

type LogLevel string

LogLevel represents the available log levels.

const (
	LevelDebug LogLevel = "debug"
	LevelInfo  LogLevel = "info"
	LevelWarn  LogLevel = "warn"
	LevelError LogLevel = "error"
)

type Logger

type Logger struct {
	*slog.Logger
	// contains filtered or unexported fields
}

Logger wraps slog.Logger with additional functionality.

func Default

func Default() *Logger

Default returns the default logger instance.

func New

func New(cfg Config) (*Logger, error)

New creates a new structured logger with the given configuration.

func NewDefault

func NewDefault() *Logger

NewDefault creates a logger with default configuration.

func (*Logger) ErrorDaemon

func (l *Logger) ErrorDaemon(msg string, err error, fields ...any)

ErrorDaemon logs daemon-related errors.

func (*Logger) ErrorDatabase

func (l *Logger) ErrorDatabase(msg string, err error, fields ...any)

ErrorDatabase logs database-related errors.

func (*Logger) ErrorDiscovery

func (l *Logger) ErrorDiscovery(msg, network string, err error, fields ...any)

ErrorDiscovery logs discovery-related errors.

func (*Logger) ErrorScan

func (l *Logger) ErrorScan(msg, target string, err error, fields ...any)

ErrorScan logs scan-related errors.

func (*Logger) InfoDaemon

func (l *Logger) InfoDaemon(msg string, fields ...any)

InfoDaemon logs daemon-related information.

func (*Logger) InfoDatabase

func (l *Logger) InfoDatabase(msg string, fields ...any)

InfoDatabase logs database-related information.

func (*Logger) InfoDiscovery

func (l *Logger) InfoDiscovery(msg, network string, fields ...any)

InfoDiscovery logs discovery-related information.

func (*Logger) InfoScan

func (l *Logger) InfoScan(msg, target string, fields ...any)

InfoScan logs scan-related information.

func (*Logger) WithComponent

func (l *Logger) WithComponent(component string) *Logger

WithComponent adds a component field to the logger.

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) *Logger

WithContext adds context to the logger for structured logging.

func (*Logger) WithError

func (l *Logger) WithError(err error) *Logger

WithError adds an error field to the logger.

func (*Logger) WithFields

func (l *Logger) WithFields(fields ...any) *Logger

WithFields adds structured fields to the logger.

func (*Logger) WithScanID

func (l *Logger) WithScanID(scanID string) *Logger

WithScanID adds a scan ID field to the logger.

func (*Logger) WithTarget

func (l *Logger) WithTarget(target string) *Logger

WithTarget adds a target field to the logger.

Jump to

Keyboard shortcuts

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