File tree Expand file tree Collapse file tree 3 files changed +7
-2
lines changed Expand file tree Collapse file tree 3 files changed +7
-2
lines changed Original file line number Diff line number Diff line change 15
15
package common
16
16
17
17
import (
18
+ "io"
18
19
"os"
19
20
21
+ "github.com/6543/logfile-open"
20
22
"github.com/rs/zerolog"
21
23
"github.com/rs/zerolog/log"
22
24
"github.com/urfave/cli/v2"
@@ -55,14 +57,14 @@ func SetupGlobalLogger(c *cli.Context) {
55
57
noColor := c .Bool ("nocolor" )
56
58
logFile := c .String ("log-file" )
57
59
58
- var file * os. File
60
+ var file io. ReadWriteCloser
59
61
switch logFile {
60
62
case "" , "stderr" : // default case
61
63
file = os .Stderr
62
64
case "stdout" :
63
65
file = os .Stdout
64
66
default : // a file was set
65
- openFile , err := os . OpenFile ( logFile , os . O_CREATE | os . O_WRONLY | os . O_APPEND , 0o660 )
67
+ openFile , err := logfile . OpenFileWithContext ( c . Context , logFile , 0o660 )
66
68
if err != nil {
67
69
log .Fatal ().Err (err ).Msgf ("could not open log file '%s'" , logFile )
68
70
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ require (
6
6
code.gitea.io/sdk/gitea v0.15.1-0.20221016183512-2d9ee57af1e0
7
7
codeberg.org/6543/go-yaml2json v1.0.0
8
8
codeberg.org/6543/xyaml v1.1.0
9
+ github.com/6543/logfile-open v1.1.1
9
10
github.com/alessio/shellescape v1.4.1
10
11
github.com/antonmedv/expr v1.12.5
11
12
github.com/bmatcuk/doublestar/v4 v4.6.0
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ gitea.com/6543/xorm v1.3.3-0.20230807141308-fc77a3b490a8/go.mod h1:qFJGFoVYbbIdn
10
10
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s =
11
11
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a /go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU =
12
12
gitee.com/travelliu/dm v1.8.11192 /go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE =
13
+ github.com/6543/logfile-open v1.1.1 h1:OKBz2GwxGaJRAOZehsSAl9antvHDG3yq83cpQcQ26aw =
14
+ github.com/6543/logfile-open v1.1.1 /go.mod h1:ZoEy7pW2mexmQxiZIqPCeh8vUxVuiHYXmSZNbvEb51g =
13
15
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0 /go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw =
14
16
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0 /go.mod h1:HcM1YX14R7CJcghJGOYCgdezslRSVzqwLf/q+4Y2r/0 =
15
17
github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0 /go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8 =
You can’t perform that action at this time.
0 commit comments