Skip to main content

logger.go

logger.go - Overview

This file defines the Logger interface and related logging functions for BadgerDB. It provides a consistent way to handle logging within the database.

Detailed Documentation

type Logger

type Logger interface {
Errorf(string, ...interface{})
Warningf(string, ...interface{})
Infof(string, ...interface{})
Debugf(string, ...interface{})
}
  • Purpose: Logger interface defines the methods a logging system must implement to be used by BadgerDB.
  • Methods:
    • Errorf: Logs an error message.
    • Warningf: Logs a warning message.
    • Infof: Logs an informational message.
    • Debugf: Logs a debug message.

func (opt *Options) Errorf

func (opt *Options) Errorf(format string, v ...interface{})
  • Purpose: Logs an ERROR log message using the logger specified in the options.
  • Parameters:
    • opt: Pointer to the Options struct.
    • format: The format string for the log message.
    • v: Variadic arguments to be formatted into the log message.

func (opt *Options) Infof

func (opt *Options) Infof(format string, v ...interface{})
  • Purpose: Logs an INFO log message using the logger specified in the options.
  • Parameters:
    • opt: Pointer to the Options struct.
    • format: The format string for the log message.
    • v: Variadic arguments to be formatted into the log message.

func (opt *Options) Warningf

func (opt *Options) Warningf(format string, v ...interface{})
  • Purpose: Logs a WARNING log message using the logger specified in the options.
  • Parameters:
    • opt: Pointer to the Options struct.
    • format: The format string for the log message.
    • v: Variadic arguments to be formatted into the log message.

func (opt *Options) Debugf

func (opt *Options) Debugf(format string, v ...interface{})
  • Purpose: Logs a DEBUG log message using the logger specified in the options.
  • Parameters:
    • opt: Pointer to the Options struct.
    • format: The format string for the log message.
    • v: Variadic arguments to be formatted into the log message.

type loggingLevel

type loggingLevel int
  • Purpose: Defines the different logging levels.

const (DEBUG loggingLevel = iota ... ERROR loggingLevel = iota)

const (
DEBUG loggingLevel = iota
INFO
WARNING
ERROR
)
  • Purpose: Enumerates the different logging levels.

type defaultLog

type defaultLog struct {
*log.Logger
level loggingLevel
}
  • Purpose: defaultLog is the default logger implementation.
  • Fields:
    • Logger: Embedded log.Logger from the standard library.
    • level: The logging level for this logger.

func defaultLogger

func defaultLogger(level loggingLevel) *defaultLog
  • Purpose: Creates a new defaultLog instance.
  • Parameters:
    • level: The logging level for the new logger.
  • Returns: A pointer to the new defaultLog instance.

func (l *defaultLog) Errorf

func (l *defaultLog) Errorf(f string, v ...interface{})
  • Purpose: Logs an error message if the logger's level is at or below ERROR.
  • Parameters:
    • l: Pointer to the defaultLog struct.
    • f: The format string for the log message.
    • v: Variadic arguments to be formatted into the log message.

func (l *defaultLog) Warningf

func (l *defaultLog) Warningf(f string, v ...interface{})
  • Purpose: Logs a warning message if the logger's level is at or below WARNING.
  • Parameters:
    • l: Pointer to the defaultLog struct.
    • f: The format string for the log message.
    • v: Variadic arguments to be formatted into the log message.

func (l *defaultLog) Infof

func (l *defaultLog) Infof(f string, v ...interface{})
  • Purpose: Logs an informational message if the logger's level is at or below INFO.
  • Parameters:
    • l: Pointer to the defaultLog struct.
    • f: The format string for the log message.
    • v: Variadic arguments to be formatted into the log message.

func (l *defaultLog) Debugf

func (l *defaultLog) Debugf(f string, v ...interface{})
  • Purpose: Logs a debug message if the logger's level is at or below DEBUG.
  • Parameters:
    • l: Pointer to the defaultLog struct.
    • f: The format string for the log message.
    • v: Variadic arguments to be formatted into the log message.

Getting Started Relevance