Skip to content

Add docker. prefix to container logger names, to enable log level to be set across all loggers#3018

Closed
vcvitaly wants to merge 4 commits intotestcontainers:mainfrom
vcvitaly-forks:3016/root_overrides_container_logging_settings
Closed

Add docker. prefix to container logger names, to enable log level to be set across all loggers#3018
vcvitaly wants to merge 4 commits intotestcontainers:mainfrom
vcvitaly-forks:3016/root_overrides_container_logging_settings

Conversation

@vcvitaly
Copy link
Copy Markdown
Contributor

Fixes #3016

@vcvitaly
Copy link
Copy Markdown
Contributor Author

@bsideup please review?

@hmemcpy
Copy link
Copy Markdown

hmemcpy commented Oct 8, 2020

Sorry for the bump, any chance of reviewing this? I have a feeling this may help deal with #637 where it would be nice to set the log level for all dockers at once instead of matching against the 🐳...

@rnorth
Copy link
Copy Markdown
Member

rnorth commented Oct 15, 2020

@vcvitaly please could you merge from master, or preferably give maintainers permission to edit?

We've had some CI problems, so hopefully updating from master should fix things.

@rnorth
Copy link
Copy Markdown
Member

rnorth commented Oct 15, 2020

Overall I think this looks fine and long overdue (sorry for the immense time to review). Let's just see the tests pass once rebased onto master and I think we should be good to go!

@rnorth rnorth added this to the next milestone Oct 15, 2020
@rnorth rnorth changed the title Update logging settings for containers #3016 Add docker. prefix to container logger names, to enable log level to be set across all loggers Oct 15, 2020
@rnorth
Copy link
Copy Markdown
Member

rnorth commented Oct 15, 2020

I think it would be fair to say this fixes #637, although not in the way originally proposed.

@vcvitaly
Copy link
Copy Markdown
Contributor Author

@rnorth I just can't find that checkbox to allow edits, I don't have it for some reason. I rebased onto the master.

rnorth
rnorth previously approved these changes Oct 17, 2020
Copy link
Copy Markdown
Member

@rnorth rnorth left a comment

Choose a reason for hiding this comment

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

Thanks @vcvitaly, LGTM.
Heads up @bsideup, @kiview, this is a slight change in aesthetics, but I think is unavoidable!

@rnorth
Copy link
Copy Markdown
Member

rnorth commented Nov 5, 2020

I’m afraid I’ll have to defer this to 1.15.1, so that we can review this together. We’re expecting to publish that release soon after 1.15.0, so it shouldn’t be too much delay.

@rnorth rnorth modified the milestones: 1.15.0, 1.15.1 Nov 5, 2020
@bsideup bsideup removed this from the 1.15.1 milestone Dec 11, 2020
@rnorth rnorth added this to the next milestone Dec 12, 2020
@bsideup bsideup removed this from the next milestone Feb 11, 2021
@perlun
Copy link
Copy Markdown
Contributor

perlun commented Jun 2, 2021

@rnorth Anything blocking this from being merged now, given that 1.15.1 is released? Would be incredibly nice to make the container logging be more easily controlled from e.g. logback-test.xml config.

@rnorth
Copy link
Copy Markdown
Member

rnorth commented Jun 9, 2021

@bsideup I think you had some ideas about how this could be done without a change to how it looks for normal use cases?

return LoggerFactory.getLogger("docker[" + abbreviatedName + "]");
}
return LoggerFactory.getLogger(String.format(
"docker.%s[%s]",
Copy link
Copy Markdown

@adutra adutra Aug 9, 2021

Choose a reason for hiding this comment

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

I'd suggest avoiding brackets here. Some frameworks (e.g. Quarkus) give brackets a special meaning, and as a consequence, the following configuration would fail:

quarkus.log.category."docker.[foo:latest]".level=ERROR

Of course, this would work:

quarkus.log.category.docker.level=ERROR

But then we lose the ability to distinguish different containers.

I think a better approach would be to create a hierarchy of docker.<image name>.<label>, separated by dots.

Also, IMHO the little whale emoji is pretty, but only adds clutter when included in a logger name. Maybe move it to the log messages themselves?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree @adutra. The whale emoji is cute but it totally doesn't belong in the actual logger name. 😂 So something like this would be preferable here:

        return LoggerFactory.getLogger("docker." + abbreviatedName);

Ideally, I think it should be prefixed with org.testcontainers though, so that all Testcontainers-based logging can be filtered away easily. org.testcontainers.docker would perhaps be the most suitable prefix here, i.e. this:

        return LoggerFactory.getLogger("org.testcontainers.docker." + abbreviatedName);

@perlun
Copy link
Copy Markdown
Contributor

perlun commented Sep 7, 2021

Ping @bsideup, would be great to get your feedback on this. (Not myself advocating a particular solution, only eager to see #637 resolved one way or the other)

@okorz001
Copy link
Copy Markdown

any progress on this? it is a bit more difficult to promote this library when logging is difficult to configure.

(personally, I would prefer an org.testcontainers. prefix, but anything other than root will solve my problems.)

@sideeffffect
Copy link
Copy Markdown

sideeffffect commented Sep 29, 2022

Humble ping 🙂
org.testcontainers. is definitely better.

@kiview
Copy link
Copy Markdown
Member

kiview commented Sep 30, 2022

Sorry, everyone, I am not sure why we let this go stale for some time now. We will look into it so that we can decide at least whether we will tackle this in a timely manner, or not at all.

@perlun
Copy link
Copy Markdown
Contributor

perlun commented Oct 25, 2022

Sorry, everyone, I am not sure why we let this go stale for some time now. We will look into it so that we can decide at least whether we will tackle this in a timely manner, or not at all.

Sounds good @kiview, any updates on this yet? ☺️

@perlun
Copy link
Copy Markdown
Contributor

perlun commented Oct 27, 2022

@vcvitaly - I added some feedback in https://github.com/testcontainers/testcontainers-java/pull/3018/files#r1006459726. If you're still with us, it would be nice to get these final details sorted out before this hopefully gets merged.

If not, I am willing to take ownership of this change to make it be mergable. We really, really need to get this shipped anytime soon. It's a major pain related to e.g. CI logging right now.

@vcvitaly
Copy link
Copy Markdown
Contributor Author

vcvitaly commented Nov 7, 2022

@vcvitaly - I added some feedback in https://github.com/testcontainers/testcontainers-java/pull/3018/files#r1006459726. If you're still with us, it would be nice to get these final details sorted out before this hopefully gets merged.

If not, I am willing to take ownership of this change to make it be mergable. We really, really need to get this shipped anytime soon. It's a major pain related to e.g. CI logging right now.

@perlun sorry, I almost forgot about this PR) let me review this within two days

@vcvitaly vcvitaly requested a review from a team November 7, 2022 18:31
@vcvitaly
Copy link
Copy Markdown
Contributor Author

vcvitaly commented Nov 8, 2022

@kiview I renamed the logger as suggested by the community, please provide your feedback.

@perlun
Copy link
Copy Markdown
Contributor

perlun commented Nov 15, 2022

Ping @kiview, is this mergable now or would it require any further adjustments?

@perlun
Copy link
Copy Markdown
Contributor

perlun commented Dec 14, 2022

@eddumelendez - you seem to have been merging stuff recently. If you could help push things forward on this, it would be very greatly appreciated. 🙇 🙏

@perlun
Copy link
Copy Markdown
Contributor

perlun commented Jan 9, 2023

Anyone who talks to the maintainers recently, please ping them about this. I seem to be unable to get in touch with them despite repeated attempts.

@eddumelendez
Copy link
Copy Markdown
Member

Hi, sorry for the delay on this one. We just started discussing about this internally. So, we will be sharing news hopefully soon.

Thanks for your patience.

@vcvitaly
Copy link
Copy Markdown
Contributor Author

@eddumelendez quite some time has passed since the PR was opened so here is a short review of the reasons why I opened it:

  1. The initial problem was that since the container logs start with the whale emoji or docker prefix, they go under the root INFO hierarchy, and you cannot see debug logs that might be useful if there are issues. I experienced that myself when I was working on another PR to testcontainers and couldn't find an issue for a while because it was printed as debug and effectively not shown. What I did - I just removed the whale emoji from the factory and added the 'docker' prefix with the DEBUG level to the logback-test.xml because I thought that missing debug info is a mistake. I now understand that it was probably a conscious decision.
  2. Since then multiple community members have made complaints that it's hard to configure logging with the whale emoji and that a non-Unicode prefix should be used. I then changed the prefix to org.testcontainers.docker as suggested by @perlun

If something else is required from my side that might speed up pr review, I'd be happy to provide any additional info.

Copy link
Copy Markdown
Member

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, @vcvitaly ! Sorry about the delay. I've left some comments. Can you also update the docs related to logging, please?

The reason why tc has been decided it is because we want to avoid log truncation.

} else {
return LoggerFactory.getLogger("docker[" + abbreviatedName + "]");
}
return LoggerFactory.getLogger("org.testcontainers.docker." + abbreviatedName);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return LoggerFactory.getLogger("org.testcontainers.docker." + abbreviatedName);
return LoggerFactory.getLogger("tc." + abbreviatedName);


assertThat(event.getFormattedMessage()).isEqualTo("some text");
assertThat(event.getLevel()).isEqualTo(Level.DEBUG);
assertThat(event.getLoggerName()).startsWith("org.testcontainers.docker");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
assertThat(event.getLoggerName()).startsWith("org.testcontainers.docker");
assertThat(event.getLoggerName()).startsWith("tc");

<logger name="org.testcontainers.shaded" level="WARN"/>

</configuration> No newline at end of file
</configuration>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we rollback this, please?


@Test
public void debugIsNotSwallowedForContainerLogs() {
// Arrange
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Arrange

listAppender.start();
LOGGER.addAppender(listAppender);

// Act
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Act

// Act
LOGGER.debug("some text");

// Assert
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Assert

@eddumelendez
Copy link
Copy Markdown
Member

#6781 has been created in order to tackle this. Thanks for your contribution @vcvitaly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loggers provided by DockerLoggerFactory inherit from root logger instead of custom loggers

10 participants