aws / aws-network-policy-agent

Apache License 2.0
45 stars 29 forks source link

Logging to /dev/stdout breaks /dev/stdout after rotation occurs #167

Closed dave-powell-kensho closed 9 months ago

dave-powell-kensho commented 10 months ago

What happened:

Set logging to stdout by passing arg --log-file=/dev/stdout. After some hours/quantity of logs it appears that a log rotation occurs, moving the symlink /dev/stdout and beginning a new file in its place.

Attach logs

# ls -al /dev/stdout*
-rw-------. 1 root root 67108864 Dec 19 17:55 /dev/stdout
lrwxrwxrwx. 1 root root       15 Dec 18 18:20 /dev/stdout-2023-12-19T07-40-03.471 -> /proc/self/fd/1
-rw-------. 1 root root        0 Dec 19 07:40 /dev/stdout-2023-12-19T07-40-03.471.gz

What you expected to happen: No log rotation when logging to /dev/stdout (or /dev/stderr)

How to reproduce it (as minimally and precisely as possible): Set arg --log-file=/dev/stdout and generate enough output/wait long enough for a log rotation to take place.

Anything else we need to know?: This is from the ECR image distribution, 602401143452.dkr.ecr.us-east-1.amazonaws.com/amazon/aws-network-policy-agent:v1.0.5

Environment:

jdn5126 commented 10 months ago

@dave-powell-kensho I see that log rotate support was added in https://github.com/aws/aws-network-policy-agent/pull/87, which does appear to be present in v1.5.0.

From looking at https://github.com/aws/aws-network-policy-agent/blob/main/pkg/logger/logger.go#L84, I am wondering if the problem is you using the string /dev/stdout instead of just stdout as the code seems to check for. Can you try stdout?

dave-powell-kensho commented 9 months ago

@dave-powell-kensho I see that log rotate support was added in #87, which does appear to be present in v1.5.0.

From looking at https://github.com/aws/aws-network-policy-agent/blob/main/pkg/logger/logger.go#L84, I am wondering if the problem is you using the string /dev/stdout instead of just stdout as the code seems to check for. Can you try stdout?

Changing to just stdout did fix the issue. Thanks for looking into this!