This commit is contained in:
Suyono 2023-09-05 13:09:53 +10:00
parent 9f7c004105
commit a5a019b28b

51
log/process.go Normal file
View File

@ -0,0 +1,51 @@
package log
import (
"fmt"
"os"
"github.com/spf13/viper"
)
type File struct {
path string
file *os.File
}
const (
filenameKey = "file"
)
func NewLogFile(configKey string) (*File, error) {
var err error
if viper.IsSet(configKey) {
return nil, nil
}
fileKey := fmt.Sprintf("%s.%s", configKey, filenameKey)
if !viper.IsSet(fileKey) {
return nil, fmt.Errorf("missing file key config %s", fileKey)
}
file := &File{
path: viper.GetString(fileKey),
}
if file.file, err = os.OpenFile(file.path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err != nil {
return nil, err
}
return file, nil
}
func (f *File) Write(b []byte) (int, error) {
return 0, nil
}
func (f *File) Close() error {
return f.file.Close()
}
func (f *File) Rotate() error {
return nil
}