Skip to content
This repository was archived by the owner on Apr 5, 2020. It is now read-only.

Log context#239

Merged
kiesel merged 5 commits intoxp-framework:masterfrom
mrosoiu:log-context
Feb 28, 2013
Merged

Log context#239
kiesel merged 5 commits intoxp-framework:masterfrom
mrosoiu:log-context

Conversation

@mrosoiu
Copy link
Member

@mrosoiu mrosoiu commented Feb 21, 2013

Hi,

This pull request adds context information to the logging mechanism. The following pull requests are related to this one: #124, #146 and #174.

Two log context implementations are provided:

More custom implementations can be added as needed; either in the framework or in an XP-Framework project.

To add context information to the logging mechanism, log.ini can be modified as follow:

[default]
appenders="util.log.FileAppender"
context="util.log.context.MappedLogContext"
appender.util.log.FileAppender.params="filename"
appender.util.log.FileAppender.param.filename="/var/log/xp/default.log"

This pull request also adds environment information to LogContext (only if the LogCategory has a LogContext attached):

  • hostname
  • runner
  • instance
  • reqource
  • params.

This info is automatically injected by the runners. It is not used anywhere in the logging output, but some custom LogContext implementation might make use of this information in it's format() method. We intend to use it in a custom Appender for the ErrorTool NG log server. If you think this adds too much overhead, I can remove it.

@xpbot
Copy link

xpbot commented Feb 21, 2013

Can one of the admins verify this patch?

Copy link
Member

Choose a reason for hiding this comment

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

The NULL !== seems unnecessary...

@kiesel
Copy link
Member

kiesel commented Feb 22, 2013

ok to test.

Happy to finally see this PR, though still I'm not 100% convinced:

  • Why are these "environment variables" being registered into the context; they're in the LogContext base class, but the two actual implementations don't include them into the format() output, so how they're supposed to be visible in the log file at the end?

@mrosoiu
Copy link
Member Author

mrosoiu commented Feb 22, 2013

@kiesel : you're right, according to YAGNI, the env variables should not be registered into the context.

I see 2 options here:

  1. Clean-up the code to remove them from the LogContext base class
  2. Add an EnvironmentLogContext implementation to make use of them in format()

What do you guys say?

@kiesel
Copy link
Member

kiesel commented Feb 22, 2013

I assume (and believe to remember from a discussion with @cconstandachi), that this is introduced because you'd need a place where all these variables are available to be collected. They're not available in any one arbitrary location in the code.

So, maybe we can trigger being handed these information at the places where it happens now, but only on demand. I propose to:

  1. Add an EnvironmentLogContext interface with all these getters and setters
  2. If a LogContext derived class implements this interface, the runners will pass in the information.
  3. It is up to the respective implementation to decide how that information is then used in the format() or toString() method

I would refrain from providing an EnvironmentLogContext implementation, as that would prevent you from being either a NDC- or MDC-backed implementation...

@mrosoiu
Copy link
Member Author

mrosoiu commented Feb 22, 2013

I refactored this PR as follow:

  1. Removed the environment variables from LogContext and transformed it to an interface. Moreover, using util.log.Layout as example, I renamed it to util.log.Context using @thekid's now famous dot notation :)
  2. Added custom toString() implementations for NestedContextLog and MappedContextLog
  3. Added util.log.context.EnvironmentAware interface and updated the runners to use it
  4. Added test classes to logging.ini (ups :) so related unit tests are now run

Let me know what you guys think.

@mrosoiu
Copy link
Member Author

mrosoiu commented Feb 22, 2013

I can remove the environment variables injection (and the interface) and add it as a new pull request later if the case. I think it can be now regarded as a separate issue.

@thekid
Copy link
Member

thekid commented Feb 28, 2013

I'm OK with this, for both 5.8 and 5.9 series. @kiesel - what do you say?

@kiesel
Copy link
Member

kiesel commented Feb 28, 2013

No objections, I'd love to see this in 5.8 and 5.9. 👍

kiesel added a commit that referenced this pull request Feb 28, 2013
@kiesel kiesel merged commit 0dbd201 into xp-framework:master Feb 28, 2013
kiesel added a commit that referenced this pull request Feb 28, 2013
kiesel pushed a commit that referenced this pull request Feb 28, 2013
kiesel pushed a commit that referenced this pull request Feb 28, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants