Merge ~troyanov/maas:agent-logs-remove-ts into maas:master

Proposed by Anton Troyanov
Status: Merged
Approved by: Adam Collard
Approved revision: 608339fa5b05fa3155bcb575b488598e746a64fa
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~troyanov/maas:agent-logs-remove-ts
Merge into: maas:master
Diff against target: 23 lines (+11/-1)
1 file modified
src/maasagent/cmd/maas-agent/main.go (+11/-1)
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
MAAS Lander Approve
Review via email: mp+459647@code.launchpad.net

Commit message

refactor(agent): remove timestamp from logs

MAAS Agent stdout is captured with systemd-cat
Because journal has it's own timestamp, we don't want to add extra

Before:
```
Jan 29 13:35:30 maas maas-agent[161449]: 1:35PM INF Logger is configured with log level "info"
Jan 29 13:35:30 maas maas-agent[161449]: 1:35PM INF Started Worker Namespace=default TaskQueue=qc38cw@agent:main WorkerID=qc38cw@agent:161449
Jan 29 13:35:30 maas maas-agent[161449]: 1:35PM INF Service MAAS Agent started
```

After:
```
Jan 30 15:05:04 maas maas-agent[253279]: INF Logger is configured with log level "info"
Jan 30 15:05:04 maas maas-agent[253279]: INF Started Worker Namespace=default TaskQueue=qc38cw@agent:main WorkerID=qc38cw@agent:253279
Jan 30 15:05:04 maas maas-agent[253279]: INF Service MAAS Agent started
```

To post a comment you must log in.
Revision history for this message
Adam Collard (adam-collard) :
Revision history for this message
Adam Collard (adam-collard) wrote :

I think the change is good, we should have tests that assert about the behaviour of the logger.

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b agent-logs-remove-ts lp:~troyanov/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 608339fa5b05fa3155bcb575b488598e746a64fa

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasagent/cmd/maas-agent/main.go b/src/maasagent/cmd/maas-agent/main.go
2index 64d893c..5e01329 100644
3--- a/src/maasagent/cmd/maas-agent/main.go
4+++ b/src/maasagent/cmd/maas-agent/main.go
5@@ -45,7 +45,17 @@ type config struct {
6 }
7
8 func Run() int {
9- log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
10+ // Use custom ConsoleWriter without TimestampFieldName, because stdout
11+ // is captured with systemd-cat
12+ // TODO: write directly to the journal
13+ consoleWriter := zerolog.ConsoleWriter{Out: os.Stdout, NoColor: true}
14+ consoleWriter.PartsOrder = []string{
15+ zerolog.LevelFieldName,
16+ zerolog.CallerFieldName,
17+ zerolog.MessageFieldName,
18+ }
19+
20+ log.Logger = zerolog.New(consoleWriter).With().Logger()
21
22 cfg, err := getConfig()
23 if err != nil {

Subscribers

People subscribed via source and target branches