Skip to content

Commit 3da1eec

Browse files
cbrockingtondansanduleac
authored andcommitted
Discard getServiceStatus logging to avoid log explosion (#61)
Querying the service status can happen any number of times between service 'start's. Since log truncating only happens on start, this can cause unchecked growth of service loggers.
1 parent c6f0586 commit 3da1eec

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

init/cli/logging.go

100755100644
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package cli
1717
import (
1818
"fmt"
1919
"io"
20+
"io/ioutil"
2021
"os"
2122

2223
"github.com/pkg/errors"
@@ -78,3 +79,15 @@ func (f *FileLoggers) OpenFile(path string) (*os.File, error) {
7879
}
7980
return file, nil
8081
}
82+
83+
var devNull = launchlib.NoopClosingWriter{Writer: ioutil.Discard}
84+
85+
type DevNullLoggers struct{}
86+
87+
func (d *DevNullLoggers) PrimaryLogger() (io.WriteCloser, error) {
88+
return &devNull, nil
89+
}
90+
91+
func (d *DevNullLoggers) SubProcessLogger(name string) launchlib.CreateLogger {
92+
return d.PrimaryLogger
93+
}

init/cli/status.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ If exit code is nonzero, writes an error message to stderr and var/log/startup.l
3636
}
3737

3838
func status(ctx cli.Context, loggers launchlib.ServiceLoggers) error {
39-
serviceStatus, err := getServiceStatus(ctx, loggers)
39+
// Executed with logging for errors, however we discard the verbose logging of getServiceStatus
40+
serviceStatus, err := getServiceStatus(ctx, &DevNullLoggers{})
4041
if err != nil {
4142
return logErrorAndReturnWithExitCode(ctx, errors.Wrap(err, "failed to determine service status"), 4)
4243
}

integration_test/-

Whitespace-only changes.

0 commit comments

Comments
 (0)