Skip to content

RABBITMQ_LOGS=- prevents logging to other sources altogether #4303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lukebakken opened this issue Mar 18, 2022 · 15 comments
Closed

RABBITMQ_LOGS=- prevents logging to other sources altogether #4303

lukebakken opened this issue Mar 18, 2022 · 15 comments
Assignees

Comments

@lukebakken
Copy link
Collaborator

https://groups.google.com/g/rabbitmq-users/c/j1AY7lBWI6c/m/kUMOb5wnAwAJ

When you run RabbitMQ from an official docker image, the following env variable is set:

RABBITMQ_LOGS=-

This is what prevents the logging exchange from starting, even though that exchange is defined in the configuration file. I can reproduce the behavior outside of Docker if I run RabbitMQ like this:

RABBITMQ_LOGS=- RABBITMQ_ALLOW_INPUT=true RABBITMQ_CONFIG_FILE="/home/lbakken/development/lukebakken/rabbitmq-users-j1AY7lBWI6c/rabbitmq.conf" ./sbin/rabbitmq-server

As a workaround, you can build an image with a custom entrypoint that unsets the RABBITMQ_LOGS env variable. I have updated this repo with just that workaround and it DOES fix the issue:

https://github.com/lukebakken/rabbitmq-users-j1AY7lBWI6c/blob/main/Dockerfile

After reading the source code, it looks like setting the RABBITMQ_LOG env var may be a better solution for Docker, but I can't seem to figure out the right syntax to enable both the console log and exchange log.

https://github.com/rabbitmq/rabbitmq-server/blob/master/deps/rabbit/src/rabbit_prelaunch_logging.erl#L1094

The above suggests the following should work:

RABBITMQ_LOG='console=debug,+color,exchange=debug'

But it does not enable the exchange logger. In addition, I don't see how the parsing could work since commas are used to delineate per-logger configuration as well as the overall loggers themselves. This form makes more sense:

RABBITMQ_LOG='console=debug,+color:exchange=debug'

@dumbbell we should discuss.

@michaelklishin
Copy link
Collaborator

Those who use rabbitmq.conf settings should have none of these problems.

@lukebakken
Copy link
Collaborator Author

@michaelklishin unfortunately the env vars take precedence.

@dumbbell
Copy link
Collaborator

dumbbell commented Mar 18, 2022

Environment variables in general are meant to override any configuration files to allow one to quickly run RabbitMQ with a different setting without touching those configuration files. So yes, setting RABBITMQ_LOGS=... is expected to override the configuration file. In other words, RABBITMQ_LOGS and RABBITMQ_LOG are only useful when starting RabbitMQ to try or debug things. They are not designed to configure RabbitMQ in production.

RABBITMQ_LOG syntax is a list of the following elements, separated by commas:

  • $level (debug to emergency)
  • $category=$level, where $category is something like "prelaunch", "channel", "mirroring", ...
  • $modifier, where $modifier is "+color", "-color", "+json", "-json", ...

In particular, exchange or console are not categories.

To enable the exchange logging output, you should be able to set RABBITMQ_LOGS=exchange:.

Update: I fixed the line above: it was RABBITMQ_LOG=exchange: instead of RABBITMQ_LOGS=exchange:.

@dumbbell
Copy link
Collaborator

To me, the following is a bug in the docker image:

When you run RabbitMQ from an official docker image, the following env variable is set:

RABBITMQ_LOGS=-

@lukebakken
Copy link
Collaborator Author

How does RABBITMQ_LOG=exchange: fit into the syntax you described? I'd like to document that variable better.

It sounds like we need to change how the Docker image configures logging. I'll open a related issue in that repo.

@dumbbell
Copy link
Collaborator

Sorry, I meant RABBITMQ_LOGS=exchange: in my previous comment. I fixed it.

@michaelklishin
Copy link
Collaborator

My point is that environment variables should never be used for what can be configured in rabbitmq.conf. We have been telling this to the Docker image community for a few years now. Here is one obvious example of how some things cannot be reasonably well expressed in a single string.

So I agree that an unconditional RABBITMQ_LOGS=- in the image is an issue that must be addressed there.

@dumbbell
Copy link
Collaborator

dumbbell commented Mar 18, 2022

RabbitMQ now supports several configuration files. On Unix, it will load all files found in $SYS_PREFIX/etc/rabbitmq/conf.d by default.

It should be easy for people packaging RabbitMQ to write their default values in $SYS_PREFIX/etc/rabbitmq/conf.d/00-default.conf for instance. Then users can add their own configuration snippets in additional files in that directory.

@lukebakken
Copy link
Collaborator Author

I like it @dumbbell. I'll open an issue and PR for the docker image, and will get to documenting these vars a bit better on the website.

Have a great weekend!

@lukebakken
Copy link
Collaborator Author

lukebakken commented Mar 18, 2022

@jeremy-evidos
Copy link

Hello,

Looks like omitting RABBITMQ_LOGS=- from the Dockerfile seems to break JSON logging set with RABBITMQ_LOG=+json. When adding RABBITMQ_LOGS=- again JSON logging starts working again. If there is a configuration option for enabling JSON logging I can add to /etc/rabbitmq/conf.d/ I'd prefer that but it seems only the environment variable was extended according to #2861.

Best,

Jeremy

@michaelklishin
Copy link
Collaborator

log.file.formatter = json

@michaelklishin
Copy link
Collaborator

So apparently there are both log.file.formatter = json and log.console.formatter = json, and neither is documented.

@jeremy-evidos
Copy link

Thanks! Adding log.console.formatter = json did the trick.

michaelklishin added a commit to rabbitmq/rabbitmq-website that referenced this issue Mar 31, 2022
such as those used
by JSON logging.

References rabbitmq/rabbitmq-server#4303
michaelklishin added a commit to rabbitmq/rabbitmq-website that referenced this issue Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants