Add filemanager api

This commit is contained in:
世界 2023-04-21 17:29:00 +08:00
parent b6068cea6b
commit 98c2c439aa
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
11 changed files with 77 additions and 54 deletions

View file

@ -1,14 +1,15 @@
package log
import (
"context"
"io"
"os"
"time"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/service/filemanager"
)
type factoryWithFile struct {
@ -36,6 +37,7 @@ func (f *observableFactoryWithFile) Close() error {
}
type Options struct {
Context context.Context
Options option.LogOptions
Observable bool
DefaultWriter io.Writer
@ -65,7 +67,7 @@ func New(options Options) (Factory, error) {
logWriter = os.Stdout
default:
var err error
logFile, err = os.OpenFile(C.BasePath(logOptions.Output), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
logFile, err = filemanager.OpenFile(options.Context, logOptions.Output, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return nil, err
}