Java Logging messages following a custom regex pattern - java.util.logging

I have various modules logging information using various levels. I would like to implement a controller that would log the information only if the message follows certain pattern.
For example -
Module A
logger.info("log this message - A");
Module B
logger.info("log this message - B");
Module C
logger.info("don't log this message - C");
I cannot make changes to A and B to change their level as the number of modules talking to each other is huge.
I would like to have a logging.properties that would log all messages not having "don't log this messages*" pattern.
Can you assist me?

There is no regex filter included with the logging package in the JDK. However, you can create your own Filter to throw out messages that match your regex then install it on the handler you want to filter. If you want to install a custom filter on a specific logger then you have to use the config property to programmatically install the filter.

Related

How does multi-line logging work in Lambda -> CloudWatch

My multi-line logging events all end up multi-events - one event per line. According to the documentation:
Each call to LambdaLogger.log() results in a CloudWatch Logs event...
but then:
However, note that AWS Lambda treats each line returned by System.out
and System.err as a separate event.
Looking inside LambdaAppender's source code, it seems that it proceeds to log the event to System.out anyway. So does that mean multi-line messages will always be broken down into multiple event?
I have read about configuring the multi_line_start_pattern, but that seems only applicable when you get to deploy a log agent, which isn't accessible in Lambda.
[Edit] LambdaAppender logs to LambdaLogger which logs to System.out.
[Edit] I found some post where a workaround was suggested - use '\r' for the eol when printing the messages. This seems to work for messages that my code produces. Stack traces logged everywhere are still a problem.
[Edit] I have been using two workarounds:
Log complex data structures (e.g. sizable maps) in JSON. CloudWatch actually recognizes JSON strings in log events, and pretty print them.
Replace '\n' with '\r'. For stack traces I created a utility method (this is in Kotlin, but the idea is generic enough):
fun formatThrowable(t: Throwable): String {
val buffer = StringWriter()
t.printStackTrace(PrintWriter(buffer))
return buffer.toString().replace("\n", "\r")
}
I think in the long run a more ideal solution would be an Appender implementation that decorates ConsoleAppender, which would do the \r replacement on all messages passing through.
Best practice is to use json in your logs. Instead of sending multiline outputs, send a formatted json (regardless of the language you are using, you will find a lib that already does that for you)
You will be amazed how easy it gets to browse your logs from there. For instance, aws cloudwatch insights automatically detects your fields, it allow to parse them and query them within seconds
I suggest to use the project slf4j-simple-lambda and to refer to this blog for more explanations.
Using slf4j and slf4j-simple-lambda is solving elegantly your problem and the solution stay lightweight. The project includes the usage of the parameter org.slf4j.simpleLogger.newlineMethod which is there to solve this problem. By default, its value is auto and should be able to detect automatically the need for manual newline handling.
Discloser: I am co-author of slf4j-simple-lambda and author of the blog.

change or add data to Sidekiq Web UI

I'm using sidekiq Pro and usually monitor my workers' process on their Web UI. Whenever there's an Error, the task is moved to Retries tab where the queue name and an error messsage are displayed. The thing is I would like to add data to this message (specifically class name and line number), but i havent found information about this anywhere. Is it possible to edit/configure the Web UI display? If that's so, how?
Is it possible to edit/configure the Web UI display? If that's so,
how?
Yes, it is possible. One way to achieve additional monitoring information is building a custom UI page. You gonna need to define a module containing request handling logics and register that module as a Sidekiq web page:
module WebAddition
def self.registered(app)
app.get('/desired_path') do
# you can define #instance_variables for passing into template
# Sidekiq uses erb for its templates so you should do it aswell
erb File.read(path_to_desired_erb_file)
end
end
end
# here we instruct Sidekiq to take our UI extension onboard
Sidekiq::Web.register WebAddition
# in case you want to provide localization, it's achieved here
Sidekiq::Web.locales << File.expand_path(File.dirname(__FILE__) + "/web/locales")
# the name of your tab (at the left hand) gonna be translated
# using the provided locale file (if any).
# right hand of the equation should be equal to the path you specified
# in registered() method
Sidekiq::Web.tabs['disappeared_jobs'] = 'desired_path'
Another option (although strongly not recommended) could be to monkeypatch Sidekiq UI code itself. Take a look at Sidekiq WebApplication class, change the methods you're intrested in and update according *.erb files located in web/views folder.

How to check text field via regex in Youtrack

How to check text field in youtrack with regexp in statemachine or stateless rule? I want to check that Review field contains link on upsource host, like: "assert Field.Regexp(regexp here)"
PS Or maybe I can do it with youtrack-upsource integration?
Keramblock, unfortunately it is not possible (neither via workflow nor via YT-UP integration).
However, you can probably solve your issue with startsWith or contains methods:
assert Review.startsWith("http://upsource", opts): <message>;
or
assert Review.contains("upsource", opts): <message>;

Custom business service in data validation manager

I have DVM fired from task flow. There is a set of certain rules, and one of them looks like this:
InvokeServiceMethod("StringUtilsBS","matchRegExp","source=eval([Client Last Name]),pattern='" + [&Mask]'","result") <> "INVALID"
The business service itself works correctly in the BS simulator: I can see valid results and logs (tracing is enabled). But when DVM is invoking this rule, there is no trace log, it looks like the service is not launching at all.
BS was compiled into all possible locales. In client's cfg I've added Business Service Query Access List=StringUtilsBS, same thing is done in "Administration: Server Configuration: Enterprise: Parameters" for a thin client.
No luck so far. Tested in high interactivity and open UI for either thin or thick clients.
I've never used the data validation manager... However, I would start by checking that your rule expression is ok, because InvokeServiceMethod syntax is quite ugly and there is a chance that you have a typo somewhere in it. In fact, I think there is one:
pattern='" + [&Mask]'", <-- this is what you have
pattern='" + [&Mask] + "'", <-- but shouldn't it be like this?
If that doesn't fix it, I would create a calculated field in the same BC where [Client Last Name] is, with the same expression. You'd have to replace [&Mask] with something else, of course, but it shouldn't make any difference.

Logging and filtering using log4cxx

I am working on the application where I need logging and filtering feature.
I am using c++. I came to know about the log4cxx support logging.
I am getting difficulty in filtering .
I have five fields
MAcID
Date and time
Command type
Status
Text Msg
I need to store these 5 fields in the log file and filter it as well based on below filtering option. Logging and filtering will be done at run time itself. Once the file size reaches 10 MiB, it will start rewriting the file from the beginning.
Filtering Options
1. MAcID
2. date and time
Filtering can done by filtering either one or both.
Result should return all the field in the log file .
Is it possible to store more than one field in the log file using log4CXX?
How to filter the information based on above mentioned criteria?
Do I need to write my own filter class inheriting from existing filter classes?
Do I need to write customise logger class to store 5 field in the log file?
I faced once a similar problem than points 1 and 4. I read log4cxx code and I found a possible solution. A job mate tested the solution and progressed it. His conclusions can be found here.
We asked in the log4cxx mailing list if it was the right solution and this is the answer we got. I hope that helps.
I don't think that log4cxx is the right tools for your task, and I am not really sure if this can be done at all with log4cxx.
You can start with a custom appender and your own log level and your own filter.
Do get it running you need to set a log level do determine which filter field should be used and when ever you change the filter you need to clear the Filters and set a new one.
Then you can extract the log string, search for your filter and let it decide if you want to output the log message or not.