Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogInfo ¶
LogInfo represents parameters used to manage logging throughout a program.
**Attributes:**
Dir: A string representing the directory where the log file is located. File: An afero.File object representing the log file. FileName: A string representing the name of the log file. Path: A string representing the full path to the log file.
func CreateLogFile ¶
CreateLogFile creates a log file in a 'logs' subdirectory of the specified directory. The log file's name is the provided log name with the extension '.log'.
**Parameters:**
fs: An afero.Fs instance to mock filesystem for testing. logDir: A string for the directory where 'logs' subdirectory and log file should be created. logName: A string for the name of the log file to be created.
**Returns:**
LogInfo: A LogInfo struct with information about the log file, including its directory, file pointer, file name, and path. error: An error, if an issue occurs while creating the directory or the log file.
Example ¶
package main
import (
"fmt"
"github.com/l50/goutils/v2/logging"
"github.com/spf13/afero"
)
func main() {
fs := afero.NewOsFs()
logDir := "/tmp"
logName := "test.log"
logInfo, err := logging.CreateLogFile(fs, logDir, logName)
if err != nil {
fmt.Printf("failed to create log file: %v", err)
return
}
fmt.Printf("log file created at: %s", logInfo.Path)
// Clean up
err = fs.Remove(logInfo.Path)
if err != nil {
fmt.Printf("failed to clean up: %v", err)
}
}
Output: log file created at: /tmp/logs/test.log