From 4ae16bce8c6aa8e3d96ca69015d2065badee3994 Mon Sep 17 00:00:00 2001 From: Daenney Date: Mon, 21 Aug 2023 20:07:55 +0200 Subject: [feature] Make log format configurable (#2130) * [feature] Don't emit timestamp in log lines When running gotosocial with a service manager like systemd, or a container runtime, the associated log driver usually emits timestamps itself. In those cases, having the extra timestamp from our own log lines ends up being a bit noisy and when centrally ingesting logs is duplicate information. This introduces a configuration flag that allows disabling emitting the timestamp. It's only wired up for "daemonised" processes, meaning server and testrig. * [chore] Add docs for log-timestamp * [feature] Simplify timestamp handling Co-Authored-By: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> * [chore] Less escaped double-quotes * [chore] Fix help string --------- Co-authored-by: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> --- internal/log/syslog_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'internal/log/syslog_test.go') diff --git a/internal/log/syslog_test.go b/internal/log/syslog_test.go index e7e82ec58..7432e61b3 100644 --- a/internal/log/syslog_test.go +++ b/internal/log/syslog_test.go @@ -71,6 +71,22 @@ func (suite *SyslogTestSuite) TestSyslog() { suite.Regexp(regexp.MustCompile(`timestamp=.* func=.* level=INFO msg="this is a test of the emergency broadcast system!"`), entry["content"]) } +func (suite *SyslogTestSuite) TestSyslogDisableTimestamp() { + // Get the current format. + timefmt := log.TimeFormat() + + // Set an empty timestamp. + log.SetTimeFormat("") + + // Set old timestamp on return. + defer log.SetTimeFormat(timefmt) + + log.Info(nil, "this is a test of the emergency broadcast system!") + + entry := <-suite.syslogChannel + suite.Regexp(regexp.MustCompile(`func=.* level=INFO msg="this is a test of the emergency broadcast system!"`), entry["content"]) +} + func (suite *SyslogTestSuite) TestSyslogLongMessage() { log.Warn(nil, longMessage) -- cgit v1.2.3