log

package
v1.0.31 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

README

The log package is used by Go services to log messages to STDOUT.

How To Use

To use the log package you first need to import the library into your project:

import "github.com/IOTechSystems/go-mod-edge-utils/pkg/log"

To send a log message to STDOUT, you first need to create a Logger with desired Log Level and then you can send log messages (indicating the log level of the message using one of the various log function calls).

logger = log.InitLogger("SERVICE_NAME", configuration.LogLevel, nil) 

logger.Info("Something interesting")
logger.Infof("Starting %s %s ", internal.CoreDataServiceKey, edgex.Version)
logger.Errorf("Something bad happened: %s", err.Error())

Log messages can be logged as Info, Debug, Trace, Warn, or Error

Documentation

Index

Constants

View Source
const (
	TraceLog = "TRACE"
	DebugLog = "DEBUG"
	InfoLog  = "INFO"
	WarnLog  = "WARN"
	ErrorLog = "ERROR"
)

These constants identify the log levels in order of increasing severity.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	// SetLogLevel sets minimum severity log level. If a logging method is called with a lower level of severity than
	// what is set, it will result in no output.
	SetLogLevel(logLevel string) error
	// LogLevel returns the current log level setting
	LogLevel() string
	// Debug logs a message at the DEBUG severity level
	Debug(msg string, args ...any)
	// Error logs a message at the ERROR severity level
	Error(msg string, args ...any)
	// Info logs a message at the INFO severity level
	Info(msg string, args ...any)
	// Trace logs a message at the TRACE severity level
	Trace(msg string, args ...any)
	// Warn logs a message at the WARN severity level
	Warn(msg string, args ...any)
	// Debugf logs a formatted message at the DEBUG severity level
	Debugf(msg string, args ...any)
	// Errorf logs a formatted message at the ERROR severity level
	Errorf(msg string, args ...any)
	// Infof logs a formatted message at the INFO severity level
	Infof(msg string, args ...any)
	// Tracef logs a formatted message at the TRACE severity level
	Tracef(msg string, args ...any)
	// Warnf logs a formatted message at the WARN severity level
	Warnf(msg string, args ...any)
}

Logger defines the interface for logging operations.

func InitLogger

func InitLogger(owningServiceName string, logLevel string, logWriter io.Writer) Logger

InitLogger creates an instance of Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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