I have a filter which is suppressing repeated messages, if the message was seen more than x times within y seconds for z seconds. With log4j I've put a event scoped MDC property to it once the threshold was reached, like:
event.setProperty( "prefix", suppressProlog );
In my layouts I used then this kind of pattern:
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS z}] %p %t %c %X{prefix} %m%n" />
As this property was limited to the current event, I hadn't to worry about cleaning up.
With log4j2, it seems that event linked properties are gone. How would I realize the same behaviour as I had with log4j?
Here's what I see as possible solutions, but none looks very appealing to me:
I could keep my own ThreadLocal property and clean it up after it was logged, but what when it's being logged through Async Logger within another Thread, or how do I know that this can be cleaned up? And splitting the suppression logic into Filter and Layout seems wrong
Reading this answer https://stackoverflow.com/a/29597669/1377224, it seems like subclassing LogEvent is discouraged either, so extending LogEvent to provide some suppress flag isn't working. As well I tried to keep away from hacking into log4j this time.
The filter could log itself a message telling that message x is going to be suppressed. Would it be good practice to have plugins log messages with standard loggers instead of StatusLogger?
What is the anticipated pattern to have filter influence, the logging output?
The sourcecode of the LoggerEvent shows that under the hood of the getProperty and setProperty methods it was using the MDC to store and get the properties.
The new class LogEvent has the
Map getContextMap()
This is the replacement from my POV.
Related
We're logging to Elastic through the Serilog dotnet package and have noticed that properties that we add to the Poerperties part of the log events seem to be suffixed with _ (underscore) and then some type identifier. For example:
This causes some issues for us in the indexing process. I've been looking through the Serilog library code to try to find the source of this but without any luck. Can someone point me in the right direction as to where the suffix is added to the property names?
It looks like you're overriding the ElasticsearchSinkOptions.CustomFormatter with code to do this when constructing the sink. Using the default formatter (leaving this un-set) should not result in this style of property name.
If this doesn't cover it, please post as much as you can to show how the sink is being configured in your app.
See also:
https://github.com/serilog-contrib/serilog-sinks-elasticsearch#a-note-about-fields-inside-elasticsearch
https://github.com/serilog-contrib/serilog-sinks-elasticsearch/issues/184
It appears that xsl:message does not work (i.e. no output is generated to message list) within an accumulator-rule. However, I don't see anything in the spec that disallows this.
<xsl:accumulator name="acc1" streamable="yes" initial-value="1">
<xsl:accumulator-rule match="cdf:ContestSelection">
<xsl:message>Output</xsl:message>
</xsl:accumulator-rule>
<xsl:accumulator>
There's all sort of possible reasons for this: the accumulator is never used, the rule never fires, the optimizer optimizes the call on xsl:message away, etc. One would need a complete repro to see what is actually going on.
Note that pretty well everything about xsl:message is implementation-defined, and one reason for that is to give the processor maximum freedom for optimization.
I'm using grails.
In some groovy classes declared in the src I want to have extensive log, with many details.
I need to have details like the method name and line number for extensive debug session of a critical component. So I use a pattern like that:
layout:pattern(conversionPattern: '%d{ABSOLUTE} %5p [%c{3}].%M:%L %m %n')
But whatever the way I declare my loggers (#Commons or #Slf4j on top of the class, or direct use a LogFactory), I only end up with some garbage info about the current method/line number.
With #Log4j annotation I got lines like:
date DEBUG [my.package.MyClass].call:? my message
With #Commons:
date DEBUG [my.package.MyClass].debug:128 my debug message
date INFO [my.package.MyClass].info:128 my info
where the line number is coming from the logger itself
At the same time hibernate logs are formatted the right way and give me meaningful output:
11:12:11,767 TRACE [descriptor.sql.BasicExtractor].extract:71 found [62364] as column [TL5_4_0_]
where extract:71 is really where the log occured.
So grails (or groovy) is messing around the logging pattern and I'm looking for a way to get the info I need on my logs lines.
How can I fix that?
When freeglut is compiled with _DEBUG it outputs a lot of warnings of different types when an event occurs, such as: 'LeaveNotify', 'MotionNotify' and 'ButtonPress'. Some of these are more useful than others depending on the situation. Specifically, 'MotionNotify' basically spams my debug logs as it is generated on mouse motion.
I am looking for a way to control the warning level by disabling warnings by type.
I have looked into FREEGLUT_PRINT_WARNING , but this does not work. Warnings are printed either with this defined or undefined. Even if it worked, I am still looking for a finer-grained solution.
I have also looked into glutInitWarningFunc to set a callback for warning printing. The callback function receives the formatted string for printing and the corresponding list of arguments. Warnings can be disabled entirely with this, but I see no other option besides string comparison for filtering what should actually get printed. As I see it, comparing strings in at least every mouse movement would be heavy.
I'm running Ant with output fed to a log file:
ant -logfile file.txt target-name
I'd also like to print some simple progress information to the console though. The answer seems to be a BuildEvent listener that writes to the console every time a new target is hit, but the documentation explicitly states:
A listener must not access System.out and System.err directly since ouput on these streams is redirected by Ant's core to the build event system.
Did I miss something? Is there a way to do this?
Ant replaces the System.out & System.err streams to remap messages printed there through it's own logging system.
That said, you can still get access to the ACTUAL OS streams by using java.io.FileDescriptor#out
Actually, the answer is Log4jListener.
There is a sample log4j configuration for logging into both console and file shown in the above link. You can then use an <echo> task with an appropriate level parameter to selectively decide what gets printed to console.
Thanks for the answers! I'm slow, but this is still something that I'd like to get right.
I've managed to get something working more or less like I want using carej's suggested approach with the java.io.FileDescriptor#out stream and an Ant scriptdef like this:
<scriptdef name="progress-text" language="javascript" >
output = new java.io.PrintStream(new java.io.FileOutputStream(java.io.FileDescriptor.err))
output.println(self.text)
</scriptdef>
Now I'm just left wondering how wize is this approach? Is there inherit risk in using the underlying OS streams directly?
EDIT:
2 Points which might be useful to anyone else with a similar question:
This article has a very good description of the Ant I/O system: http://codefeed.com/blog/?p=68
java.lang.System does something very similar to set System.out and System.err in the first place.
All of this gave me a little more confidence in this approach.