How to generate 2 log files; One will log Hibernate sql messages generated by show-sql = true property. And another will log rest of the Hibernate logs.
I have configured logback.xml as shown below:
<logger name="org.hibernate" level="debug" additivity="false">
<appender-ref ref="hibernate" />
</logger>
<logger name="org.hibernate.SQL" additivity="false">
<appender-ref ref="hibernate-sql" />
</logger>
It is generating 2 log files as expected. However, It is duplicating hibernate-sql log messages in Tomcat console, hibernate appender, and hibernate-sql appender.
How could I restrict logback to generate Hibernate sql logs in hibernate-sql appender only?
Hibernate writes the generated SQL in two distinct and completely separate ways. When you set the property hibernate.show_sql to true, it tells Hibernate to write generated SQL to stdout. No logging framework is involved in this in any way. That's why you should pretty much never use it. Just remove that property from your config, and the SQL in the Tomcat console will go away.
The second way Hibernate writes the SQL, and the way you should use, is that it sends it to the logging framework under the org.hibernate.SQL logging category. It has no connection at all with hibernate.show_sql.
As an additional tidbit, in case you don't know, Hibernate also logs all values bound to parameters of the prepared statements using the org.hibernate.type category. This is something you can't get with hibernate.show_sql, so using Hibernate's logging instead of show_sql is both more flexible and more informative.
Related
I'm using Karate for validation tests.
I setup a retry on one of my request but sometimes there is more than 100 retry, this create to big useless logs with the same big payload on each request...
And this bloat my CI.
I want to reduce this logs quantity, maybe by disable log for just this request ?
I've tried * configure report = false but this disable only on Cucumber html report.
I want to disable also in STDOUT console.
So maybe with some form of log level manipulation setted in the logback-test.xml ?
Thanks.
No you con't disable logs per request, you can switch off everything by setting the log level to INFO - but I guess you don't want that. 100 retries sounds very unusual to me. You can try your luck with a feature request - but I can tell you that this would be low priority unless someone contributes code.
If this really bothers you, write some custom Java code to do this polling + HTTP request and call it from Karate.
EDIT: I think I have a solution that will work for you. You can completely disable the Karate logs appearing on the console - while still having the HTML report with this change to the logback-test.xml:
<root level="warn">
<!-- <appender-ref ref="STDOUT" /> -->
<appender-ref ref="FILE" />
</root>
So just commenting out the console log appender will do the trick !
Also read: https://github.com/intuit/karate#report-verbosity
I want the internal logging statements from EclipseLink (version 2.7.x) to be logged through my Log4j2 setup.
I know there's a bug report on this (https://issues.apache.org/jira/browse/LOG4J2-444) which never got solved. I also know, there is a wiki how to implement an own logger (https://wiki.eclipse.org/EclipseLink/Examples/Foundation/Logging).
Since I think someone must have already addressed this problem (since there should be thousands of EclipseLink + log4j2 setups out there) and come out with a reliable solution, my question would be:
Where can i find it?
I am not sure this solution is the best, but
The library contain EclipseLink logger impelementation for slf4j:
https://search.maven.org/artifact/org.eclipse.persistence/org.eclipse.persistence.extension
You can set it to use in persistence.xml:
<property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.slf4j.SLF4JLogger" />
Now you need bridge slf4j -> log4j2:
https://search.maven.org/artifact/org.apache.logging.log4j/log4j-slf4j-impl
And finally log4j2.xml: <Logger name="eclipselink.logging" level="ALL"> ... </Logger>
level="ALL" because what exatly will be logged is configured in persistence.xml e.g. eclipselink.logging.level property an so on:
https://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging
In one of the requirement i want to integrate splunk with existing mule esb server that we are using(we are using cloudhub).
How can we achieve that?
Any help will be great.
You can use the Splunk connector to integrate within your applications. If you want to just send event data from existing applications see this other documentation page: Sending Data from Runtime Manager to External Monitoring Software
Add below configuration in your log4j file.
<Configuration packages="com.mulesoft.ch.logging.appender,com.splunk.logging">
<Http name="SPLUNK" url="https://input-prd-p-3ppsrv6qrg3h.cloud.splunk.com:8088" token="19954BDA-7A21-4FFA-A1E5-B3DFB7C75D55" disableCertificateValidation="true">
<PatternLayout pattern="%m" />
</Http>
where you should prefix "input-" to the domain name you have for splunk & the token will be the one that of http even collector.
Also while logging give reference of above http splunk appender :
<Root level="INFO">
<AppenderRef ref="SPLUNK" />
</Root>
Let me know if it works
I have a console app using Fluent NHibernate. I have configured it to log to various places using log4net. And it works great. I can see the SQL that I want to see and can sent log output to various appenders. The problem is that I cannot suppress the log4net sql output going to the console.
The extra console output is not being controlled by my log4net config settings. It always appears, no matter if I turn off all appenders.
Any suggestions?
Do you have this property set to true in your nhibernate section in your app.config?
<property name="show_sql">true</property>
If so set it to false.
Edit
Here is a sample piece of code from the nhibernate source:
log.Debug(logMessage);
if (LogToStdout)
{
Console.Out.WriteLine("NHibernate: " + statement);
}
In the above code LogToStdout is directly linked to the show_sql configuration property. If you have this set to true nothing will stop it from writing to the console. In regards to your comment you cannot control this via log4net. You can only control what you are doing with the log.Debug(logMessage) via log4net.
To disable any logs put the following code:
< add key="nhibernate-logger" value="" />
into your appSettings section.
The NHibernate logs don't help me much, I'll turn them on when I need them... I add these settings to the log4net section of my app.config:
<logger name="NHibernate">
<level value="OFF" />
</logger>
<logger name="NHibernate.SQL">
<level value="OFF" />
</logger>
Assume you are using some libraries like NHibernate or Castle ActiveRecord that use log4net internally. Your application uses log4net too. It's possible to configure all applications to save logs into file or any other output. But the problem is by enabling log4net for my own application, other programs save their log into the log file and causes it grow very fast with information that I don't need at the moment.
How can I route logs of each application to different outputs or at least how can I deny other applications from logging?
NHibernate/Castle Active Record generate lot of log information but that is all DEBUG level logging. So you can turn down your log level from "ALL" to "INFO" or "ERROR" in config file and you should be OK.
log4Net also support named logger and logger hierarchy. I am sure both NHibernate/Castle would be using named logger. So you can choose to ignore that particular named logger using configuration. See log4Net help where they have used have different logging level for Com.Foo library.
Using named logger is a typical way of separating log traces from different components/modules/libraries etc. Each application (as in different process) would have different configuration file and you can always have different log files to separate the log traces.
Just direct different loggers to different appenders.
Pseudo example:
<log4net>
<appender name="MyAppender" type="log4net.Appender.FileAppender">
<!--appender properties (file name, layout, etc)-->
</appender>
<appender name="NHAppender" type="log4net.Appender.FileAppender">
<!--ditto-->
</appender>
<logger name="MyAppMainNamespace">
<level value="INFO"/>
<appender-ref ref="MyAppender" />
</logger>
<logger name="NHibernate">
<level value="ERROR"/>
<appender-ref ref="NHAppender" />
</logger>
</log4net>