Skip to content

Improve logging significantly – color is back!#1758

Merged
georglauterbach merged 4 commits intodocker-mailserver:masterfrom
georglauterbach:logging
Jan 22, 2021
Merged

Improve logging significantly – color is back!#1758
georglauterbach merged 4 commits intodocker-mailserver:masterfrom
georglauterbach:logging

Conversation

@georglauterbach
Copy link
Copy Markdown
Member

@georglauterbach georglauterbach commented Jan 21, 2021

This one is important to me. What happened:

  1. I added an environment variable which enables users to set the log-level
  2. I re-enabled color :D See yourself:

2021-01-21-094536_701x136_scrot

  1. Enhanced some output that did not use _notify but just echo
  2. Improved supervisor configuration
  3. Got rid of (confusing) CRIT messages during startup

Here is why you should like and approve it:


First of all, the log right now is all over the place. See:

2021-01-21 00:01:16,377 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
2021-01-21 00:01:16,377 INFO Included extra file "/etc/supervisor/conf.d/saslauth.conf" during parsing
2021-01-21 00:01:16,377 INFO Included extra file "/etc/supervisor/conf.d/supervisor-app.conf" during parsing
2021-01-21 00:01:16,394 INFO RPC interface 'supervisor' initialized
2021-01-21 00:01:16,394 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2021-01-21 00:01:16,394 INFO supervisord started with pid 8
2021-01-21 00:01:17,398 INFO spawned: 'mailserver' with pid 11
 
2021-01-21 00:01:17,444 INFO success: mailserver entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
[ TASKLOG ]  Welcome to docker-mailserver!
 
[ TASKLOG ]  Initializing setup
[ TASKLOG ]  Checking configuration
[ TASKLOG ]  Configuring mail server
Cert found in /etc/letsencrypt/acme.json for mail.Domain.com

[ TASKLOG ]  Startin misc
[ TASKLOG ]  Starting mail server
2021-01-21 00:01:21,967 INFO spawned: 'cron' with pid 264
2021-01-21 00:01:21,968 INFO success: cron entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
cron: started

Let's break this down. At the moment, there is no color in our logs. With this PR, this is not the case anymore. More importantly, there are two CRIT messages, which absolutely should not be there:

2021-01-21 00:01:16,377 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.

2021-01-21 00:01:16,394 CRIT Server 'unix_http_server' running without any HTTP authentication checking

This was due to a sloppy supervisor configuration. This is now fixed. The configuration file has been cleaned up and improved.

Someone introduced a plain echo here:

Cert found in /etc/letsencrypt/acme.json for mail.itbsd.com

This is now a _notify. (Note here that I had to adjust the unit tests to not check against our own logs. We never do that and we can't because of a limitation of ANSI-escape parsing. That is absolutely fine though.)

You can see that I changed the supervisor log-level to warn. Before you light this PR up, let me explain:) Currently, you will see this next to our log:

2021-01-21 00:01:16,377 INFO Included extra file "/etc/supervisor/conf.d/saslauth.conf" during parsing
2021-01-21 00:01:16,377 INFO Included extra file "/etc/supervisor/conf.d/supervisor-app.conf" during parsing
2021-01-21 00:01:16,394 INFO RPC interface 'supervisor' initialized
2021-01-21 00:01:16,394 INFO supervisord started with pid 8
2021-01-21 00:01:17,398 INFO spawned: 'mailserver' with pid 11
 
2021-01-21 00:01:17,444 INFO success: mailserver entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)

This will now not be printed anymore. Is this a problem? I argue it's not:

This will always work, because it is baked into the Dockerfile:

2021-01-21 00:01:16,377 INFO Included extra file "/etc/supervisor/conf.d/saslauth.conf" during parsing
2021-01-21 00:01:16,377 INFO Included extra file "/etc/supervisor/conf.d/supervisor-app.conf" during parsing

If it's not, a warning is issued and you will see it. Then for

2021-01-21 00:01:16,394 INFO RPC interface 'supervisor' initialized

it's the same line of reasoning. If you#re interested in the PIDs:

2021-01-21 00:01:16,394 INFO supervisord started with pid 8
2021-01-21 00:01:17,398 INFO spawned: 'mailserver' with pid 11

run docker exec mail ps. The last message:

2021-01-21 00:01:17,444 INFO success: mailserver entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)

has the same line of reasoning as the first two arguments. Now, when start-mailserver.sh is running, the default log-level will be warn if you want (and by default). But now you have the choice. You could set it back to info.


I'd like to see this merged as fast as possible :D

@georglauterbach georglauterbach added pr/need review kind/question Someone asked a question - feel free to answer priority/high area/scripts labels Jan 21, 2021
@georglauterbach georglauterbach added this to the v8.0.0 milestone Jan 21, 2021
@georglauterbach georglauterbach requested a review from a team January 21, 2021 09:32
@georglauterbach georglauterbach self-assigned this Jan 21, 2021
@georglauterbach georglauterbach requested review from casperklein and wernerfred and removed request for a team January 21, 2021 15:56
@georglauterbach
Copy link
Copy Markdown
Member Author

georglauterbach commented Jan 21, 2021

Just FYI: This is what it will look like with log-level warn:

new_logs

Please note that I used _notify in user-patches.sh too and I changed Amavis' log level in the user-patches.sh - that's why you're not seeing it here.

Copy link
Copy Markdown
Member

@wernerfred wernerfred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

I personally like the changes you introduced to color up the output and allow setting the supervisor loglevel.

Regarding "to not break backwards compatability" my opinion (apart from this PR/change but in general) is that major releases are justified by breaking changes so if you/we think keeping the default by "warn" from now on then there is no better timing as now as we are close to 8.0.0.

Comment thread target/supervisor/supervisord.conf
Comment thread target/supervisor/supervisord.conf
@georglauterbach
Copy link
Copy Markdown
Member Author

LGTM 👍🏻

I personally like the changes you introduced to color up the output and allow setting the supervisor loglevel.

Regarding "to not break backwards compatability" my opinion (apart from this PR/change but in general) is that major releases are justified by breaking changes so if you/we think keeping the default by "warn" from now on then there is no better timing as now as we are close to 8.0.0.

I like this idea. I will adjust this PR to use warn by default.

@georglauterbach georglauterbach merged commit 324ee8e into docker-mailserver:master Jan 22, 2021
@georglauterbach georglauterbach deleted the logging branch January 22, 2021 09:03
wernerfred added a commit that referenced this pull request Jan 25, 2021
@casperklein
Copy link
Copy Markdown
Member

Now, when start-mailserver.sh is running, the default log-level will be warn if you want (and by default). But now you have the choice. You could set it back to info

Doesn't work for me. I've set it to info, but don't get any info logs. For example on container stop, there should be stuff like:

2021-02-01 00:40:02,464 WARN received SIGTERM indicating exit request
2021-02-01 00:40:02,464 INFO waiting for rsyslog, postfix, cron, amavis, changedetector, fail2ban, opendkim, opendmarc, dovecot, mailserver to die
2021-02-01 00:40:02,464 INFO stopped: mailserver (terminated by SIGTERM)

Can someone confirm this?

@georglauterbach
Copy link
Copy Markdown
Member Author

georglauterbach commented Jan 31, 2021

Now, when start-mailserver.sh is running, the default log-level will be warn if you want (and by default). But now you have the choice. You could set it back to info

Doesn't work for me. I've set it to info, but don't get any info logs. For example on container stop, there should be stuff like:


2021-02-01 00:40:02,464 WARN received SIGTERM indicating exit request

2021-02-01 00:40:02,464 INFO waiting for rsyslog, postfix, cron, amavis, changedetector, fail2ban, opendkim, opendmarc, dovecot, mailserver to die

2021-02-01 00:40:02,464 INFO stopped: mailserver (terminated by SIGTERM)

Can someone confirm this?

Do you see at least the WARN message? Can you then set SUPERVISOR_LOGLEVEL to something ridiculous, like some random string, and see if a warning is printed that the values is not recognised?

@casperklein
Copy link
Copy Markdown
Member

Yes. The warn message is always there. And the modification to supervisord.conf seems to be successful:

root@mail:/# grep loglevel /etc/supervisor/supervisord.conf
loglevel = info

@casperklein
Copy link
Copy Markdown
Member

Can you then set SUPERVISOR_LOGLEVEL to something ridiculous

That leads to this startup warning as expected:

[ WARNING ] SUPERVISOR_LOGLEVEL value 'aendeavor-told-me-so' unknown. Defaulting to 'warn'

@georglauterbach
Copy link
Copy Markdown
Member Author

georglauterbach commented Jan 31, 2021

Good. Then I suspect supervisord needs more than an update? Maybe it needs to be restarted too?

@casperklein
Copy link
Copy Markdown
Member

The Problem is, that supervisord does not seem to recognize the change.

Additional to supervisorctl update, I've also tried this without success: supervisorctl reread

@georglauterbach
Copy link
Copy Markdown
Member Author

The Problem is, that supervisord does not seem to recognize the change.

Additional to supervisorctl update, I've also tried this without success: supervisorctl reread

Is there something like a self-restart command? I investigate too, but I'll do this in a few hours:)

@casperklein
Copy link
Copy Markdown
Member

casperklein commented Feb 1, 2021

Maybe it needs to be restarted too?

I am not sure, but I don't think that is possible, as supervisor is our PID1. Killing it will stop the container.

@georglauterbach
Copy link
Copy Markdown
Member Author

georglauterbach commented Feb 1, 2021

Maybe it needs to be restarted too?

I am not sure, but I don't think that is possible, as supervisor is our PID1. Killing it will stop the container.

No, dumb-init is - you created the PR yourself :D

But, according to this forum post, first a re-read and then an update should do it. I will test this. You already tried this, I just now read it. I will try what the systemctl restart supervisord does

@georglauterbach
Copy link
Copy Markdown
Member Author

Oh my - supervisorctl reload seems to have worked...

I will provide a PR.

@casperklein
Copy link
Copy Markdown
Member

No, dumb-init is - you created the PR yourself :D

Yes, I know. Take a look at this 😉

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   2144   740 ?        Ss   11:39   0:00 /usr/bin/dumb-init -- supervisord -c /etc/supervisor/supervisord.conf

@casperklein
Copy link
Copy Markdown
Member

casperklein commented Feb 1, 2021

the default log-level will be warn if you want (and by default). But now you have the choice. You could set it back to info.

BTW Thats not 100% true. It's not fully possible to get the old behavior back. INFO messages that would appear before start-mailserver.sh modifies supervisord.conf are lost.

@georglauterbach
Copy link
Copy Markdown
Member Author

the default log-level will be warn if you want (and by default). But now you have the choice. You could set it back to info.

BTW Thats not 100% true. It's not fully possible to get the old behavior back. [...]

I made this point clear from the start:

You can see that I changed the supervisor log-level to warn. Before you light this PR up, let me explain:) Currently, you will see this next to our log:

2021-01-21 00:01:16,377 INFO Included extra file "/etc/supervisor/conf.d/saslauth.conf" during parsing
2021-01-21 00:01:16,377 INFO Included extra file "/etc/supervisor/conf.d/supervisor-app.conf" during parsing
2021-01-21 00:01:16,394 INFO RPC interface 'supervisor' initialized
2021-01-21 00:01:16,394 INFO supervisord started with pid 8
2021-01-21 00:01:17,398 INFO spawned: 'mailserver' with pid 11

2021-01-21 00:01:17,444 INFO success: mailserver entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)

This will now not be printed anymore. Is this a problem? I argue it's not...

Only these 5 INFO messages are "lost", and I believe this to be fine.

#1778 should take care of the rest.

@casperklein
Copy link
Copy Markdown
Member

Sorry for not being more precise. I had read it and it's fine. But I thought that should be mentioned in the README?

When someone sets a log level, then the assumption probably is, that no messages are suppressed in that log level. For example you set it to debug for some reason, you could be wondering why there a no debug message from the startup until start-mailserver is invoked.

@georglauterbach
Copy link
Copy Markdown
Member Author

Sorry for not being more precise. I had read it and it's fine. But I thought that should be mentioned in the README?

When someone sets a log level, then the assumption probably is, that no messages are suppressed in that log level. For example you set it to debug for some reason, you could be wondering why there a no debug message from the startup until start-mailserver is invoked.

We could add this to mailserver.env, if you want. I think it's not that important, since this project is not debugging supervisord, and the messages are only for PIDs and loaded conf files, which cannot be altered before anyway:)

Comment thread test/mail_ssl_letsencrypt.bats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/scripts kind/question Someone asked a question - feel free to answer priority/high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants