Log4j2 logs are in different patterns - log4j2

In our project we have multiple modules. Rest module will call another module say M1. Rest is using Log4j1 and module M1 upgraded to Log4j2 2.13.1. Interesting part is all the logs in rest module displaying in one format and other module(when rest called) logs are displayed in different format as below.
Rest module displays logs as below.
INFO | rest controller 1
INFO | rest service layer
Other module shows different format as below. Not sure why it is showing this format. Both are logged in rest log file with differnet formats. is this the default format?
2020-03-29 23:34:54.316 INFO 18602 --- [container1] c.t.v.c.a.Handler : Wating for the result

So your REST module is using Log4j 1 with a configuration file. Your M1 modules is using Log4j 2 with a different configuration file. Log4j 1 and Log4j 2 will not be sharing the same configuration file as they use different configuration syntax. However, it seems both are configured to write to the same file.
You should replace your log4j 1.x jar with the log4j-1.2-api jar from Log4j 2. This will cause the module using log4j 1.x to use Log4j 2 instead and everything will log with the same format.

Related

Neo4j 3+ logging customization

Is there any way to customize logging on Neo4j 3+? Something like logback.xml where I can define log pattern, output files, levels, rolling policy and so on.
If you're talking about using Neo4j Server, then the logging configuration is available in the neo4j.conf file, with options prefixed by dbms.logs.: https://neo4j.com/docs/operations-manual/current/reference/configuration-settings/
These options include log level, output files, rotation policy, etc.
If you're using Neo4j embedded in another application (which you probably shouldn't), then you can use the setUserLogProvider(...) of the GraphDatabaseFactory. If you want to route user logging to another framework, there is a Slf4jLogProvider in the neo4j-logging jar, which can be used to send logs to slf4j and onto wherever you like.

Log4j is already not configured via logback.groovy file in Grails 3.2.8

As we know by default logging in Grails 3.0 is handled by the Logback logging framework and can be configured with the grails-app/conf/logback.groovy file. The good part of this was that the configuration inside this file was applicable for the Logback and Log4j implementations (tested successfully in Grails 3.1.2). After we migrated to use Grails 3.2.8 from Grails 3.1.2 (as I said before), it seems that the configuration inside the logback.groovy file is not used by the Log4j and it should be configured in other way - at runtime.
I made a deep research in this to ensure that this is really the way it is configured now and it seems that if I am using the default Log4j logging:
org.apache.log4j.Logger.getLogger("name").info("TEST");
is not working at all. To make the information populated into the output log file, I should use the default SLF4J API:
org.slf4j.LoggerFactory.getLogger("name").info("TEST");
The problem here is because that we have a lot of places in the code where the logging is implemented using Log4j approach and now - nothing is written in the log file.
So I have two questions here. The first one - is this the exact way how Grails implemented this behavior (as nothing is mentioned in the official documentation - Grails 3.2.8 Documentation). The second one - is the XML or RUNTIME configurations are the best way to configure the Log4j, so use it as before. If yes - the bad thing here is that we should maintain two same configurations at a time. Is there any other way to configure the Log4j to use the same configuration as the Grails Logger.
P.S. There is no need to publish any code, as all are just default configurations.
Thanks a lot!
appender('STDOUT', ConsoleAppender) {
encoder(PatternLayoutEncoder) {
charset = Charset.forName('UTF-8')
}
}
root(ERROR, ['STDOUT'])
logger("<package_name>", DEBUG)
List artifacts = ["conf", "controllers", "domain", "init"]
artifacts.each { artifact ->
logger("grails.app.${artifact}.<package_name>", DEBUG)
}
After writing this, you can add logger for debugging in any artifacts mentioned above like:
log.debug "Any Message"
For more setting you can read here: https://logback.qos.ch/manual/groovy.html

JBoss 6.x throwing java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl

In our application we make WSDL service call(let us say "SomeService"). We use JBoss 6.x and JDK1.8 in our environment(test). Our application also has dependency with CXF for some other services. "SomeService" should be called through standard JAXWS instead of "CXF". By default,c all is being routed through CXF and that's resulting into policy issues. Hence, I followed the solution mentioned below:
JAX-WS = When Apache CXF is installed it "steals" default JDK JAX-WS implementation, how to solve? .
I made the following change in my code:
if (previousDelegate.getClass().getName().contains("cxf")) {
ServiceDelegate serviceDelegate = ((Provider) Class.forName("com.sun.xml.internal.ws.spi.ProviderImpl").newInstance())
.createServiceDelegate(SomeService.WSDL_LOCATION, SomeService.SERVICE_NAME, service.getClass());
delegateField.set(service, serviceDelegate);
}
This change works fine for me in my local environment(I'm using Tomcat 8 +JDK 1.8). I went and deployed the code in test platform (it's JBoss 6.x + JDK 1.8). While testing the functionality, I'm getting the following error:
java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl from [Module "deployment.MyAPP.war:main" from Service Module Loader]
Not sure of the reason for this error. Anybody has clues about it? Do we need to make any additional changes in our JBoss server. Since "com.sun.xml.internal.ws.spi.ProviderImpl" is standard class and that's available in JDK1.8, I don't see any reason why am I getting the above error since our JBoss server is pointing to JDK1.8.
Your help is highly appreciated.
It looks like a classloading issue with your application, or the application server.
The ClassNotFoundException will occur the first time the class is referenced and the classloader tries to load it. The next time the class is referenced, the classloader has cached that is is not found and will throw a NoClassDefFoundError.
Confirm that the ClassNotFoundException is not being caused by the class not being packaged correctly or other classloader settings. Also, ensure the ClassNotFoundException is not occurring the first time the class is referenced.
Check to see if there are any symlinks in the JBoss path.
That will tell us the classes you have deployed to your application, and allow us check if com.sun.xml.internal.ws.spi.ProviderImpl or a related class is deployed to it. That class is shipped with the application server in this directory, and I think this should be the only location it is loaded from.
src/jboss-as/thirdparty/sun-jaxws/lib/jaxws-rt.jar
The only reference I can find to the message "classLoader is not connected to a domain (probably undeployed?) for class "
If you are using a custom JAX-WS implementation and don't want to use JBossWS CXF (the supported JAX-WS library that comes with EAP 6.x), you'll need to first remove JBossWS from your deployment
Once you've done that, you then need to expose the JDK classes that represent the JAX-WS and SAAJ implementation.
Make sure you add modules dependencies for sun.internal.saaj and sun.internal.ws to your deployment.
--
Anup

Grails 2.5.0: way to fill database automatically

I have a business web application made with Grails 2.5.0.
In this application, I use a GSP form to upload files and to fill a database.
In fact, I upload httpd conf files from a directory and I extract informations from them.
Now, I want to find a solution to do the same automatically. But I didn't find solution.
I tried Spring Batch plugin but it does work with Grails 2.5.0.Other Batch plugin seems too old to work.
Other way, it perhaps to import files at startup but I don't know if you can read files from a directory at startup ( e.g : from /var/myapp/conf ).
If you want to execute something when the application starts add it to BootStrap.groovy

IIS Log Parser-Python

Apachelog parser is a nice Project which can be used to parse a apache log file. Are there any other python modules to parse an IIS log file other than this one?
I am using a regex pattern to parse IIS log files and feed them into fluent, and then elasticsearch.
Here is the pattern:
/^(?<time>\d{4}\-\d{2}\-\d{2}\s+\d{2}\:\d{2}\:\d{2}\s+)(?<s_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s+)(?<cs_method>.+?\s+)(?<cs_uri_stem>.+?\s+)(?<cs_uri_query>.+?\s+)(?<s_port>\d{1,3}\s+)(?<user>.+?\s+)(?<c_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s+)(?<csUser_agent>.+?\s+)(?<sc_status>\d{1,3}\s+)(?<sc_substatus>\d{1,3}\s+)(?<sc_win32_status>\d+\s+)(?<sc_bytes>\d+\s+)(?<cs_bytes>\d+\s+)(?<time_taken>\d+)?$/
This leaves out User Agent info though.
Hope it gets you going.

Resources