mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
22 lines
440 B
Go
22 lines
440 B
Go
package accesslog
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"sync"
|
|
|
|
"github.com/yusing/go-proxy/internal/task"
|
|
)
|
|
|
|
type File struct {
|
|
*os.File
|
|
sync.Mutex
|
|
}
|
|
|
|
func NewFileAccessLogger(parent task.Parent, cfg *Config) (*AccessLogger, error) {
|
|
f, err := os.OpenFile(cfg.Path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("access log open error: %w", err)
|
|
}
|
|
return NewAccessLogger(parent, &File{File: f}, cfg), nil
|
|
}
|