Files
golib/hlog/logfile.go
2026-01-01 14:54:14 +11:00

24 lines
479 B
Go

package hlog
import (
"os"
"path/filepath"
"github.com/pkg/errors"
)
// Returns a pointer to a new log file with the specified path.
// Remember to call file.Close() when finished writing to the log file
func NewLogFile(path string) (*os.File, error) {
logPath := filepath.Join(path, "server.log")
file, err := os.OpenFile(
logPath,
os.O_APPEND|os.O_CREATE|os.O_WRONLY,
0663,
)
if err != nil {
return nil, errors.Wrap(err, "os.OpenFile")
}
return file, nil
}