logging

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 4 Imported by: 1

README

goutils/v2/logging

The logging package is a part of goutils library. It provides utility functions for logging operations in Go.


Functions

CreateLogFile
func CreateLogFile(logDir string, logName string) (LogInfo, error)

Create a log file in a directory named logs, which is a subdirectory of the given directory.


Installation

To use the goutils/v2/logging package, you need to install it via go get:

go get github.com/l50/goutils/v2/logging

Usage

After installation, you can import it in your project:

import "github.com/l50/goutils/v2/logging"

Tests

To run the tests for the goutils/v2/logging package, navigate to your $GOPATH/src/github.com/l50/goutils/v2/logging directory and run go test:

go test -v

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.


License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogInfo

type LogInfo struct {
	Dir      string
	FilePtr  *os.File
	FileName string
	Path     string
}

LogInfo contains parameters used to provide logging throughout a program.

func CreateLogFile

func CreateLogFile(logDir string, logName string) (LogInfo, error)

CreateLogFile creates a log file in a directory named logs, which is a subdirectory of the given directory. The log file's name is the base name of the given directory with the extension .log.

Parameters:

logDir: A string representing the directory where the logs subdirectory should be created.

Returns:

LogInfo: A struct containing information about the log file, including its directory, file pointer, file name, and path.

error: An error if the log file or its parent directory cannot be created.

Example:

logDir := "/path/to/logDir" logName := "stuff.log" logInfo, err := logging.CreateLogFile(logDir, logName)

if err != nil {
  fmt.Printf("failed to create log file: %v", err)
}

fmt.Printf("Log file created at: %s", logInfo.Path)

Jump to

Keyboard shortcuts

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