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 ¶
- func AddStepLog(ctx context.Context, log logger.Logger, step *build.Step, logName string) logger.StepLogCloser
- func BuildFilename(nameParts []string, ext string) string
- func Debugf(ctx context.Context, format string, args ...interface{})
- func Errorf(ctx context.Context, format string, args ...interface{})
- func Get(ctx context.Context) logger.Logger
- func Infof(ctx context.Context, format string, args ...interface{})
- func OpenResourceLogFile(rootLogDir string, resourceName string, logFileName string) (relativeLogFilePath string, logFile *os.File, err error)
- func Warningf(ctx context.Context, format string, args ...interface{})
- func WithLogger(ctx context.Context, logger logger.Logger) context.Context
- func WriteResourceLogFile(ctx context.Context, rootLogDir string, resourceName string, ...) (relativeLogFilePath string, err error)
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 ¶
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 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 WithLogger ¶
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.