Additional info from MDC to logs (java.util.logging) - java.util.logging

Exist any possibility to add MDC to java.util.logging ?
If yes, how to reach it ?

The JDK logging is setup to just include everything you need as a log parameter.
To make the MDC work you have to create filters and or formatters that are aware of the MDC. Then install only those filters and formatters on every handler in the logging system.

Related

Is it possible to configure spdlog from a file like log4j or log4cxx?

I have experience of log4j, and have used a port of it called log4net in c#. In both cases I find it very useful to configure loggers at run time, by means of logger config files. For example you can increase the log level of a particular subsystem without a recompile.
I am searching for a logging framework for c++. Currently checking log4cxx and spdlog.
I see that log4cxx can read its configuration from an xml file.
Does this ability to configure at run time exist for spdlog?
There is https://github.com/guangie88/spdlog_setup to configure spdlog using TOML

Determine whether I'm running on Cloudhub or Locally

I am building a Mulesoft/Anypoint app for deployment on Cloudhub, and for diagnostic purposes want to be able to determine (from within the app) whether it is running on Cloudhub or in Anypoint Studio on my local development machine:
On Cloudhub, I want to use the Cloudhub connector to create notifications for exceptional situations - but using that connector locally causes an exception.
On my local machine, I want to use very verbose logs with full dumping of the payload (#[message.payloadAs(java.lang.String)]) but want to use much more concise logging when on Cloudhub.
What's the best way to distinguish the current runtime? I can't figure out any automatic system properties that expose this information.
(I realize the I could set my own property called something like system.env=LOCAL and override it with system.env=CLOUDHUB for deployment, but I'm curious if the platform already provides this information in some way.)
As far as I can tell the best approach is to use properties. The specific name and values you use doesn't matter as long as you're consistent. Here's an example:
In your local dev environment, set the following property in mule-app.properties:
system.environment=DEV
When you deploy to Cloudhub, use the deployment tool to change that property to:
system.environment=CLOUDHUB
Then in your message processors, you can reference this property:
<logger
message="#['${system.environment}' == 'DEV' ? 'verbose log message' : 'concise log message']"
level="ERROR"
doc:name="Exception Logger"
/>

Where can I find request and response logs for Spark?

I have just started using Spark framework. And experimenting with a local server on Mac OS
The documentation says that to enable debug logs I simply need to add a dependency.
I've added a dependency and can observe logs in the console.
The question is where the log files are located?
If you are following the Spark example here, you are only enabling slf4j-simple logging. By default, this only logs items to the console. You can change this programmatically (Class information here) or by adding a properties file to the classpath, as seen in this discussion. Beyond this you will likely want to implement a logging framework like log4j or logback, as slf4j is designed to act as a facade over an existing logging implementation.

How to disable logging while running unit-tests?

When I am testing my class, application writes lots of stuff to the console, because of logging (I am using SLF4J). How do I disable logging in this case, without introducing special flag inside tested class?
SLF4J is only a facade, meaning that it does not provide a complete logging solution, so if you are using it with LOG4J just change your logging level to OFF. For more info see https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html#OFF
So you can have two log4j.xml configuration files, one for production and one for testing with logging level set to OFF or better to WARN.

Monitoring Active Directory events

How can I programatically detect any changes that occur to Microsoft's Active Directory?
You could enable auditing of directory service changes, than write a script or application to query the security log for the appropriate events.
You probably need to be a bit more specific. Do you want to detect changes to one or two objects? If so, #DSO's recommendation is a good one. If you want to be able to do regular imports of all changes DirSync is probably what you need.