log

package
v0.0.0-...-cd06882 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package log provides a wrapper over logging interfaces to simplify usage in recovery lib.

If Logger not set then default golang log package is using.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddStepLog

func AddStepLog(ctx context.Context, log logger.Logger, step *build.Step, logName string) logger.StepLogCloser

AddStepLog created and adds step's log to logger.

func BuildFilename

func BuildFilename(nameParts []string, ext string) string

BuildFilename builds a log filename with a minimal timestamp prefix, all the name parts in the middle delimited by "_" with non-word characters replaced with underscores, and the provided file extension.

This not only communicates the time of the log to users, but keeps similar files in chronological order within the same directory when displayed sorted by name (alphanumerical order) by most programs.

Example result: ({"some", "log_name"}, "log") => "20220523-122753_some_log_name.log"

func Debugf

func Debugf(ctx context.Context, format string, args ...interface{})

Debugf log message at Debugf level.

func Errorf

func Errorf(ctx context.Context, format string, args ...interface{})

Errorf is like Debug, but logs at Errorf level.

func Get

func Get(ctx context.Context) logger.Logger

Get logger from context.

func Infof

func Infof(ctx context.Context, format string, args ...interface{})

Infof is like Debug, but logs at Infof level.

func OpenResourceLogFile

func OpenResourceLogFile(rootLogDir string, resourceName string, logFileName string) (relativeLogFilePath string, logFile *os.File, err error)

OpenResourceLogFile creates and opens a new file with the provided name in the log directory for the given resource under the rootLogDir. All dirs in the path are created if they do not exist.

Returns the file path of the log file, relative to the logging root, and the open file.

func Warningf

func Warningf(ctx context.Context, format string, args ...interface{})

Warningf is like Debug, but logs at Warningf level.

func WithLogger

func WithLogger(ctx context.Context, logger logger.Logger) context.Context

WithLogger sets logger to the context. If Logger is not provided process will be finished with panic.

func WriteResourceLogFile

func WriteResourceLogFile(ctx context.Context, rootLogDir string, resourceName string, logFileName string, fileContents []byte) (relativeLogFilePath string, err error)

WriteResourceLogFile writes bytes to a log file with the specified name. The log file will be created the log directory for the given resource under the rootLogDir.

Returns the file path of the log file, relative to the logging root.

Types

This section is empty.

Jump to

Keyboard shortcuts

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