Skip to content

Commit 46068fa

Browse files
acabarbayeaorabdel
andauthored
✨ [logs] Added a rolling file logger (#656)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> ### Description various fixes in the `logs` module ### Test Coverage <!-- Please put an `x` in the correct box e.g. `[x]` to indicate the testing coverage of this change. --> - [x] This change is covered by existing or additional automated tests. - [ ] Manual testing has been performed (and evidence provided) as automated testing was not feasible. - [ ] Additional tests are not required for this change (e.g. documentation update). --------- Co-authored-by: Abdelrahman Abdelraouf <abdelrahman.abdelraouf@arm.com>
1 parent 8dbd261 commit 46068fa

32 files changed

+342
-62
lines changed

changes/20250723181707.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:recycle: [logs] update slog utilities to use standard library slog rather than golang extension's implementation

changes/20250723182149.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:recycle: [logs] Update ways to not close writers when loggers close

changes/20250723185203.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: [logs] Added a rolling file logger

utils/go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.23.0
55
toolchain go1.24.1
66

77
require (
8+
github.com/DeRuina/timberjack v1.3.3
89
github.com/OneOfOne/xxhash v1.2.8
910
github.com/avast/retry-go/v4 v4.6.1
1011
github.com/bmatcuk/doublestar/v3 v3.0.0
@@ -26,7 +27,7 @@ require (
2627
github.com/hashicorp/go-cleanhttp v0.5.2
2728
github.com/hashicorp/go-hclog v1.6.3
2829
github.com/hashicorp/go-retryablehttp v0.7.8
29-
github.com/iamacarpet/go-win64api v0.0.0-20230324134531-ef6dbdd6db97
30+
github.com/iamacarpet/go-win64api v0.0.0-20240507095429-873e84e85847
3031
github.com/joho/godotenv v1.5.1
3132
github.com/mitchellh/go-homedir v1.1.0
3233
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
@@ -39,13 +40,12 @@ require (
3940
github.com/spf13/pflag v1.0.7
4041
github.com/spf13/viper v1.20.1
4142
github.com/stretchr/testify v1.10.0
42-
github.com/zailic/slogr v0.0.2-alpha
4343
go.uber.org/atomic v1.11.0
4444
go.uber.org/goleak v1.3.0
4545
go.uber.org/mock v0.5.2
4646
go.uber.org/zap v1.27.0
4747
golang.org/x/crypto v0.40.0
48-
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6
48+
golang.org/x/exp v0.0.0-20250718183923-645b1fa84792
4949
golang.org/x/mod v0.26.0
5050
golang.org/x/net v0.42.0
5151
golang.org/x/oauth2 v0.30.0
@@ -96,7 +96,7 @@ require (
9696
github.com/xanzy/ssh-agent v0.3.3 // indirect
9797
github.com/yusufpapurcu/wmi v1.2.4 // indirect
9898
go.uber.org/multierr v1.10.0 // indirect
99-
golang.org/x/tools v0.34.0 // indirect
99+
golang.org/x/tools v0.35.0 // indirect
100100
gopkg.in/warnings.v0 v0.1.2 // indirect
101101
gopkg.in/yaml.v3 v3.0.1 // indirect
102102
)

utils/go.sum

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ bitbucket.org/creachadair/stringset v0.0.9/go.mod h1:t+4WcQ4+PXTa8aQdNKe40ZP6iwe
22
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
33
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
44
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
5+
github.com/DeRuina/timberjack v1.3.2 h1:ei548+RsKNhWNCoah4X0TKnR8VWRnbjsEMFZRBbSNdU=
6+
github.com/DeRuina/timberjack v1.3.2/go.mod h1:oIz9NBX34JRQd9U3ZuSEih49LuYlFnATRWiCfwbeiJ8=
7+
github.com/DeRuina/timberjack v1.3.3 h1:R+3oEvJP1wd8iYkGGsnq9e6pHGAXFqizPKReEMj0jvQ=
8+
github.com/DeRuina/timberjack v1.3.3/go.mod h1:pbNOvT1AIUxBqiH/ytL9nNsKrHUrDGJdz7T23y79RRU=
59
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
610
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
711
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
@@ -52,6 +56,8 @@ github.com/evanphx/hclogr v0.2.0/go.mod h1:1jTbx9bMs6/CBoiPwzNobWb7BFkK/KF5XljvP
5256
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
5357
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
5458
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
59+
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
60+
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
5561
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
5662
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
5763
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -132,6 +138,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
132138
github.com/iamacarpet/go-win64api v0.0.0-20210311141720-fe38760bed28/go.mod h1:oGJx9dz0Ny7HC7U55RZ0Smd6N9p3hXP/+hOFtuYrAxM=
133139
github.com/iamacarpet/go-win64api v0.0.0-20230324134531-ef6dbdd6db97 h1:VjwKCN2PMLlMKM2k9AW8QQsfmEH43ldlX+JGeWW9cEE=
134140
github.com/iamacarpet/go-win64api v0.0.0-20230324134531-ef6dbdd6db97/go.mod h1:B7zFQPAznj+ujXel5X+LUoK3LgY6VboCdVYHZNn7gpg=
141+
github.com/iamacarpet/go-win64api v0.0.0-20240507095429-873e84e85847 h1:cRHZFGwIDgQlr9abL/P93JXR7pYxzvf0xAIt0xzwrh0=
142+
github.com/iamacarpet/go-win64api v0.0.0-20240507095429-873e84e85847/go.mod h1:B7zFQPAznj+ujXel5X+LUoK3LgY6VboCdVYHZNn7gpg=
135143
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
136144
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
137145
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
@@ -235,8 +243,6 @@ github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM
235243
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
236244
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
237245
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
238-
github.com/zailic/slogr v0.0.2-alpha h1:ZZ+96+AOnk4L9JoPkZ6aGbGXnn90/53A9zm9JcjYSYc=
239-
github.com/zailic/slogr v0.0.2-alpha/go.mod h1:cwplHb/RBT+83E4QzPcVtCs0Z/sAjmgMtC09XGm9SCU=
240246
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
241247
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
242248
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
@@ -254,6 +260,8 @@ golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
254260
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
255261
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ/GnQx2BE33L8BOHQkI=
256262
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ=
263+
golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 h1:R9PFI6EUdfVKgwKjZef7QIwGcBKu86OEFpJ9nUEP2l4=
264+
golang.org/x/exp v0.0.0-20250718183923-645b1fa84792/go.mod h1:A+z0yzpGtvnG90cToK5n2tu8UJVP2XUATh+r+sfOOOc=
257265
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
258266
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
259267
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -313,6 +321,7 @@ golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
313321
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
314322
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
315323
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
324+
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
316325
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
317326
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
318327
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=

utils/logs/fifo_logger_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212
"github.com/go-faker/faker/v4"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
15+
"go.uber.org/goleak"
1516

1617
"github.com/ARM-software/golang-utils/utils/commonerrors"
1718
"github.com/ARM-software/golang-utils/utils/commonerrors/errortest"
1819
"github.com/ARM-software/golang-utils/utils/parallelisation"
1920
)
2021

2122
func TestFIFOLoggerLineIterator(t *testing.T) {
23+
defer goleak.VerifyNone(t)
2224
t.Run("logger tests", func(t *testing.T) {
2325
loggers, err := NewFIFOLogger()
2426
require.NoError(t, err)
@@ -48,6 +50,7 @@ func TestFIFOLoggerLineIterator(t *testing.T) {
4850
}
4951

5052
func TestPlainFIFOLoggerLineIterator(t *testing.T) {
53+
defer goleak.VerifyNone(t)
5154
t.Run("logger tests", func(t *testing.T) {
5255
loggers, err := NewPlainFIFOLogger()
5356
require.NoError(t, err)

utils/logs/file_logger.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66
package logs
77

88
import (
9+
"fmt"
910
"io"
11+
"log"
12+
"time"
1013

14+
"github.com/DeRuina/timberjack"
1115
"github.com/sirupsen/logrus"
16+
17+
"github.com/ARM-software/golang-utils/utils/commonerrors"
18+
"github.com/ARM-software/golang-utils/utils/parallelisation"
19+
"github.com/ARM-software/golang-utils/utils/reflection"
20+
"github.com/ARM-software/golang-utils/utils/safecast"
21+
sizeUnits "github.com/ARM-software/golang-utils/utils/units/size"
1222
)
1323

1424
// NewFileLogger creates a logger to a file.
@@ -29,3 +39,80 @@ func NewFileOnlyLogger(logFile string, loggerSource string) (loggers Loggers, er
2939
func CreateFileLogger(logFile string, loggerSource string) (loggers Loggers, err error) {
3040
return NewFileLogger(logFile, loggerSource)
3141
}
42+
43+
type FileLoggerOptions struct {
44+
maxFileSize float64
45+
maxAge time.Duration
46+
maxBackups int
47+
}
48+
49+
type FileLoggerOption func(*FileLoggerOptions) *FileLoggerOptions
50+
51+
// WithMaxFileSize sets the maximum size in bytes of a log file before it gets rotated.
52+
func WithMaxFileSize(maxFileSize float64) FileLoggerOption {
53+
return func(o *FileLoggerOptions) *FileLoggerOptions {
54+
if o == nil {
55+
return o
56+
}
57+
o.maxFileSize = maxFileSize
58+
return o
59+
}
60+
}
61+
62+
// WithMaxAge sets the maximum duration old log files are retained.
63+
func WithMaxAge(maxAge time.Duration) FileLoggerOption {
64+
return func(o *FileLoggerOptions) *FileLoggerOptions {
65+
if o == nil {
66+
return o
67+
}
68+
// This is necessary to avoid a Race Condition
69+
if maxAge >= time.Minute {
70+
o.maxAge = maxAge
71+
}
72+
return o
73+
}
74+
}
75+
76+
// WithMaxBackups sets the maximum number of old log files to retain.
77+
func WithMaxBackups(maxBackups int) FileLoggerOption {
78+
return func(o *FileLoggerOptions) *FileLoggerOptions {
79+
if o == nil {
80+
return o
81+
}
82+
o.maxBackups = maxBackups
83+
return o
84+
}
85+
}
86+
87+
// NewRollingFilesLogger creates a rolling file logger using [lumberjack](https://github.com/natefinch/lumberjack) under the bonnet.
88+
func NewRollingFilesLogger(logFile string, loggerSource string, options ...FileLoggerOption) (loggers Loggers, err error) {
89+
opts := &FileLoggerOptions{
90+
maxFileSize: 100 * sizeUnits.MiB,
91+
maxAge: 24 * time.Hour,
92+
maxBackups: 3,
93+
}
94+
for i := range options {
95+
opts = options[i](opts)
96+
}
97+
if reflection.IsEmpty(logFile) {
98+
err = commonerrors.New(commonerrors.ErrInvalidDestination, "missing file destination")
99+
return
100+
}
101+
l := &timberjack.Logger{
102+
Filename: logFile,
103+
MaxSize: safecast.ToInt(opts.maxFileSize / sizeUnits.MiB),
104+
MaxAge: safecast.ToInt(opts.maxAge.Hours() / 24),
105+
MaxBackups: opts.maxBackups,
106+
LocalTime: false,
107+
Compress: false,
108+
}
109+
closerStore := parallelisation.NewCloserStore(false)
110+
closerStore.RegisterCloser(l)
111+
112+
loggers = &GenericLoggers{
113+
Output: log.New(l, fmt.Sprintf("[%v] Output: ", loggerSource), log.LstdFlags),
114+
Error: log.New(l, fmt.Sprintf("[%v] Error: ", loggerSource), log.LstdFlags),
115+
closeStore: closerStore,
116+
}
117+
return
118+
}

utils/logs/file_logger_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import (
1010

1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
13+
"go.uber.org/goleak"
1314

1415
"github.com/ARM-software/golang-utils/utils/filesystem"
1516
)
1617

1718
func TestFileLogger(t *testing.T) {
19+
defer goleak.VerifyNone(t)
1820
var tests = []struct {
1921
loggerCreationFunc func(path string) (Loggers, error)
2022
}{
@@ -24,10 +26,27 @@ func TestFileLogger(t *testing.T) {
2426
{
2527
loggerCreationFunc: func(path string) (Loggers, error) { return NewFileOnlyLogger(path, "Test") },
2628
},
29+
// FIXME uncomment when data race is fixed
30+
// {
31+
// loggerCreationFunc: func(path string) (Loggers, error) {
32+
// return NewRollingFilesLogger(path, "Test", WithMaxFileSize(sizeUnits.MiB), WithMaxBackups(2), WithMaxAge(10*time.Minute))
33+
// },
34+
// },
35+
// {
36+
// loggerCreationFunc: func(path string) (Loggers, error) {
37+
// return NewRollingFilesLogger(path, "Test", WithMaxAge(time.Second))
38+
// },
39+
// },
40+
// {
41+
// loggerCreationFunc: func(path string) (Loggers, error) {
42+
// return NewRollingFilesLogger(path, "Test")
43+
// },
44+
// },
2745
}
2846
for i := range tests {
2947
test := tests[i]
3048
t.Run(fmt.Sprintf("logger %v", i), func(t *testing.T) {
49+
defer goleak.VerifyNone(t)
3150
file, err := filesystem.TouchTempFileInTempDir("test-filelog-*.log")
3251
require.NoError(t, err)
3352

utils/logs/hclog_logger_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ import (
99

1010
"github.com/hashicorp/go-hclog"
1111
"github.com/stretchr/testify/require"
12+
"go.uber.org/goleak"
1213

1314
"github.com/ARM-software/golang-utils/utils/logs/logstest"
1415
)
1516

1617
func TestHclogLogger(t *testing.T) {
18+
defer goleak.VerifyNone(t)
1719
logger := hclog.New(nil)
1820
loggers, err := NewHclogLogger(logger, "Test")
1921
require.NoError(t, err)
2022
testLog(t, loggers)
2123
}
2224

2325
func TestHclogWrapper(t *testing.T) {
26+
defer goleak.VerifyNone(t)
2427
loggers, err := NewLogrLogger(logstest.NewTestLogger(t), "test")
2528
require.NoError(t, err)
2629
hcLogger, err := NewHclogWrapper(loggers)

utils/logs/json_logger.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/rs/zerolog"
1313

1414
"github.com/ARM-software/golang-utils/utils/commonerrors"
15+
"github.com/ARM-software/golang-utils/utils/parallelisation"
1516
)
1617

1718
// JSONLoggers defines a JSON logger
@@ -22,6 +23,7 @@ type JSONLoggers struct {
2223
loggerSource string
2324
writer WriterWithSource
2425
zerologger zerolog.Logger
26+
closerStore *parallelisation.CloserStore
2527
}
2628

2729
func (l *JSONLoggers) SetLogSource(source string) error {
@@ -88,16 +90,31 @@ func (l *JSONLoggers) LogError(err ...interface{}) {
8890
func (l *JSONLoggers) Close() error {
8991
l.mu.Lock()
9092
defer l.mu.Unlock()
91-
return l.writer.Close()
93+
return l.closerStore.Close()
9294
}
9395

9496
// NewJSONLogger creates a Json logger.
95-
func NewJSONLogger(writer WriterWithSource, loggerSource string, source string) (loggers Loggers, err error) {
97+
func NewJSONLogger(writer WriterWithSource, loggerSource string, source string) (Loggers, error) {
98+
return newJSONLogger(true, writer, loggerSource, source)
99+
}
100+
101+
// NewJSONLogger creates a Json logger. It is similar to NewJSONLogger but does not close the writer on Close().
102+
func NewJSONLoggerWithWriter(writer WriterWithSource, loggerSource string, source string) (Loggers, error) {
103+
return newJSONLogger(false, writer, loggerSource, source)
104+
}
105+
106+
func newJSONLogger(closeWriterOnClose bool, writer WriterWithSource, loggerSource string, source string) (loggers Loggers, err error) {
107+
closeStore := parallelisation.NewCloserStore(false)
108+
if closeWriterOnClose {
109+
closeStore.RegisterCloser(writer)
110+
}
111+
96112
zerroLogger := JSONLoggers{
97113
source: source,
98114
loggerSource: loggerSource,
99115
writer: writer,
100116
zerologger: zerolog.New(writer),
117+
closerStore: closeStore,
101118
}
102119
err = zerroLogger.Check()
103120
if err != nil {
@@ -112,8 +129,8 @@ func NewJSONLogger(writer WriterWithSource, loggerSource string, source string)
112129
return
113130
}
114131

115-
// NewJSONLoggerForSlowWriter creates a lock free, non blocking & thread safe logger
116-
// wrapped around slowWriter
132+
// NewJSONLoggerForSlowWriter creates a lock free, non-blocking & thread safe logger
133+
// wrapped around slowWriter. The slowWriter is closed on Close.
117134
//
118135
// params:
119136
// slowWriter : writer used to write data streams
@@ -126,3 +143,18 @@ func NewJSONLogger(writer WriterWithSource, loggerSource string, source string)
126143
func NewJSONLoggerForSlowWriter(slowWriter WriterWithSource, ringBufferSize int, pollInterval time.Duration, loggerSource string, source string, droppedMessagesLogger Loggers) (loggers Loggers, err error) {
127144
return NewJSONLogger(NewDiodeWriterForSlowWriter(slowWriter, ringBufferSize, pollInterval, droppedMessagesLogger), loggerSource, source)
128145
}
146+
147+
// NewJSONLoggerForSlowWriterWithoutClosingWriter creates a lock free, non-blocking & thread safe logger
148+
// wrapped around slowWriter. It is similar to NewJSONLoggerForSlowWriter but does not close the writer on Close().
149+
//
150+
// params:
151+
// slowWriter : writer used to write data streams
152+
// ringBufferSize : size of ring buffer used to receive messages
153+
// pollInterval : polling duration to check buffer content
154+
// loggerSource : logger application name
155+
// source : source string
156+
// droppedMessagesLogger : logger for dropped messages
157+
// If pollInterval is greater than 0, a poller is used otherwise a waiter is used.
158+
func NewJSONLoggerForSlowWriterWithoutClosingWriter(slowWriter WriterWithSource, ringBufferSize int, pollInterval time.Duration, loggerSource string, source string, droppedMessagesLogger Loggers) (loggers Loggers, err error) {
159+
return NewJSONLogger(NewDiodeWriterForSlowWriterWithoutClosing(slowWriter, ringBufferSize, pollInterval, droppedMessagesLogger), loggerSource, source)
160+
}

0 commit comments

Comments
 (0)