From 96910c7bea6d57d7e4095f65b917091e8a633d3d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 8 Aug 2023 04:04:02 +0200 Subject: [PATCH 1/2] Release file lock on USR1 signal --- cmd/common/logger.go | 6 ++++-- go.mod | 1 + go.sum | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/common/logger.go b/cmd/common/logger.go index c43804ffb9..52ec424ca3 100644 --- a/cmd/common/logger.go +++ b/cmd/common/logger.go @@ -15,8 +15,10 @@ package common import ( + "io" "os" + "github.com/6543/logfile-open" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" @@ -55,14 +57,14 @@ func SetupGlobalLogger(c *cli.Context) { noColor := c.Bool("nocolor") logFile := c.String("log-file") - var file *os.File + var file io.ReadWriteCloser switch logFile { case "", "stderr": // default case file = os.Stderr case "stdout": file = os.Stdout default: // a file was set - openFile, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o660) + openFile, err := logfile.OpenFileWithContext(c.Context, logFile, 0o660) if err != nil { log.Fatal().Err(err).Msgf("could not open log file '%s'", logFile) } diff --git a/go.mod b/go.mod index d242c89c65..47f02572c4 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( code.gitea.io/sdk/gitea v0.15.1-0.20221016183512-2d9ee57af1e0 codeberg.org/6543/go-yaml2json v1.0.0 codeberg.org/6543/xyaml v1.1.0 + github.com/6543/logfile-open v1.1.0 github.com/alessio/shellescape v1.4.1 github.com/antonmedv/expr v1.12.5 github.com/bmatcuk/doublestar/v4 v4.6.0 diff --git a/go.sum b/go.sum index 79b01f5767..59346ce466 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ gitea.com/6543/xorm v1.3.3-0.20230807141308-fc77a3b490a8/go.mod h1:qFJGFoVYbbIdn gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE= +github.com/6543/logfile-open v1.1.0 h1:15MQYG3WcB6hQk+m4MZYeHFIitiU4Lvr41pE6rkT4tY= +github.com/6543/logfile-open v1.1.0/go.mod h1:ZoEy7pW2mexmQxiZIqPCeh8vUxVuiHYXmSZNbvEb51g= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw= github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJcghJGOYCgdezslRSVzqwLf/q+4Y2r/0= github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8= From 4b618a55612af82d20f9f6b068d6caca9d06e0f4 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 8 Aug 2023 04:27:02 +0200 Subject: [PATCH 2/2] bump version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 47f02572c4..ba50e7f68b 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( code.gitea.io/sdk/gitea v0.15.1-0.20221016183512-2d9ee57af1e0 codeberg.org/6543/go-yaml2json v1.0.0 codeberg.org/6543/xyaml v1.1.0 - github.com/6543/logfile-open v1.1.0 + github.com/6543/logfile-open v1.1.1 github.com/alessio/shellescape v1.4.1 github.com/antonmedv/expr v1.12.5 github.com/bmatcuk/doublestar/v4 v4.6.0 diff --git a/go.sum b/go.sum index 59346ce466..e5c95852ec 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ gitea.com/6543/xorm v1.3.3-0.20230807141308-fc77a3b490a8/go.mod h1:qFJGFoVYbbIdn gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE= -github.com/6543/logfile-open v1.1.0 h1:15MQYG3WcB6hQk+m4MZYeHFIitiU4Lvr41pE6rkT4tY= -github.com/6543/logfile-open v1.1.0/go.mod h1:ZoEy7pW2mexmQxiZIqPCeh8vUxVuiHYXmSZNbvEb51g= +github.com/6543/logfile-open v1.1.1 h1:OKBz2GwxGaJRAOZehsSAl9antvHDG3yq83cpQcQ26aw= +github.com/6543/logfile-open v1.1.1/go.mod h1:ZoEy7pW2mexmQxiZIqPCeh8vUxVuiHYXmSZNbvEb51g= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw= github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJcghJGOYCgdezslRSVzqwLf/q+4Y2r/0= github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8=