[squid-users] Logging in Squid external helpers in Docker?

Alex Rousskov rousskov at measurement-factory.com
Tue Dec 28 17:06:06 UTC 2021


On 12/28/21 12:32 AM, roee klinger wrote:
> I am running Squid inside a Docker container, and I am using an external
> helper, I am trying to get the logs from the external helper to go to
> Docker logs (stdout).
> 
> Currently, I am writing the logs to a file, which works, but I would
> like to get them to stdout instead, however, Squid redirects all the
> stdout from the external helper to itself, which makes me unable to send
> the logs I want to stdout.
> 
> Is there a way for me to send the logs I want to the main stdout of the
> container and not to Squid itself?

> sys.stderr.write("test ################################################")

According to [0], Python line-buffers stderr output. Try adding a new
line to the message.

[0]
https://adamj.eu/tech/2020/06/26/how-to-check-if-pythons-output-buffering-is-enabled/

----

The rest probably does not apply to your docker, but I will record it
here in case somebody else finds it useful...

> cache_log stdio:/dev/stdout

The above trick does not work in many environments. In basic
command-line tests, I get[1,2]:

> squid.strace.2072945:openat(AT_FDCWD, "/dev/stdout",
> O_RDWR|O_CREAT|O_APPEND, 0666) = -1 EACCES (Permission denied)

> WARNING: Cannot write log file: stdio:/dev/stdout
> stdio:/dev/stdout: Permission denied
>          messages will be sent to 'stderr'.

After that, the helper stderr output will not show up on Squid _stdout_:
Since Squid processes are using stderr instead of stdout for cache_log,
the helper stderr output is being sent to the (duped) Squid stderr file
descriptor rather than a (duped) Squid stdout descriptor.

There are other subtle problems with that /dev/stdout trick. It is
essentially unsupported.


HTH,

Alex.

[1] Same problem without the "stdio:" prefix. The presence of that
prefix in the WARNING message is misleading: Even with that prefix,
Squid actually tries to open "/dev/stdout", of course.

[2] Squid cannot open /dev/stdout in many environments because that pipe
often belongs to the user starting Squid rather than the user Squid runs
as:
https://unix.stackexchange.com/questions/38538/bash-dev-stderr-permission-denied/38580


More information about the squid-users mailing list