postgres-operator icon indicating copy to clipboard operation
postgres-operator copied to clipboard

Logs should have a common patern

Open endersonmaia opened this issue 3 years ago • 0 comments

The current logs are not following a pattern.

They start with JSON, which is nice.

{"level":"info","ts":1645719468.362505,"logger":"cmd","msg":"Go Version: go1.13.3"}
{"level":"info","ts":1645719468.362529,"logger":"cmd","msg":"Go OS/Arch: linux/amd64"}
{"level":"info","ts":1645719468.3625689,"logger":"cmd","msg":"Version of operator-sdk: v0.17.1"}

Then I have something like this, no more JSON:

E0224 19:34:48.369498       1 reflector.go:153] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:105: Failed to list *v1alpha1.Postgres: postgres.db.movetokube.com is forbidden: User "system:serviceaccount:kube-system:ext-postgres-operator" cannot list resource "postgres" in API 
E0224 19:34:49.370236       1 reflector.go:153] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:105: Failed to list *unstructured.Unstructured: postgres.db.movetokube.com is forbidden: User "system:serviceaccount:kube-system:ext-postgres-operator" cannot list resource "postgres"
E0224 19:34:49.370302       1 reflector.go:153] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:105: Failed to list *unstructured.Unstructured: postgresusers.db.movetokube.com is forbidden: User "system:serviceaccount:kube-system:ext-postgres-operator" cannot list resource "post

And when I get some error to connect to the database, I get this in two lines:

2022/02/24 19:00:15 failed to connect to PostgreSQL server: parse postgresql://postgres:z6fxajZydUO6,x9QN=Hn=K-sdPsE^X@__REDACTED__/postgres?ssl=required                                                                                    
: net/url: invalid control character in URL                                                                                                                                                                                                                                                      

Proposal

Select a pattern and sitck to it.

You could go with JSON, that's easy to parse if anyone needs to make some processing before sending the logs somewhere.

If I may suggest, I'd go with something like logfmt.

See:

  • https://www.brandur.org/logfmt
  • https://www.brandur.org/canonical-log-lines
  • https://pkg.go.dev/github.com/kr/logfmt?utm_source=godoc

endersonmaia avatar Feb 24 '22 19:02 endersonmaia