How to stop seeing DEBUG output in output log Intellij IDEA? - intellij-idea

I am using third party code that uses:
if (logger.isDebugEnabled()) {
logger.debug("Message");
}
I'm getting these messages in my output even though I'm using the standard run configuration, and it's only happening on my instance of this particular project so I'm not sure what I'm missing.
I've tried deleting the run configuration and starting it again but I keep getting it in my output.
How do I stop this?
[SOLVED]

I found this in another project, copied it across and it's behaving as I would expect now:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
This was in logback.xml in src>main>resources
Thanks to those that commented!

Related

Running Gatling tests not showing testFile.log on IntelliJ

We have an issue where whenever our Gatling performance tests are run the .log file that should generate at the root of the folder is not there.
This is my whole logback file if anyone able to help please.
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter> -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
<immediateFlush>true</immediateFlush>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>testFile.log</file>
<append>false</append>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
</encoder>
</appender>
<!-- uncomment and set to DEBUG to log all failing HTTP requests -->
<!-- uncomment and set to TRACE to log all HTTP requests -->
<logger name="io.gatling.http.engine.response" level="TRACE" />
<root level="WARN">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
Thank you very much.
Update
It seems the issue may be with IntelliJ itself as noticed we can see the file when going directly to the finder.
Disabling custom plugins should help. Seems one of configuration was corrupted.
There's a good chance the file is simply not generated where you expect it. Try setting an absolute path instead to verify.

Dyanmically populating a variable in a log file

I have a web service (Jenkins) that handles user requests, and I want to be able to dynamically append the request session id to each log line without having to actually add that variable to each and every log action.
I'm using log4j2 with slf4j implementation, I initialize the logger using an external configuration file with org.apache.logging.log4j.core.config.Configurator, I create an instance of the logger per every session using
final Logger logger = LoggerFactory.getLogger(MyClass.class);
I have for example:
logger.debug("received new request");
...
logger.debug("added something");
And I want the user session id to be added to each line without having to add it myself like:
logger.debug("{} received new request",session.getId());
...
logger.debug("{} added something",session.getId());
My log4j2.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Configuration status="INFO">
<Properties>
<Property name="logPath">...</Property>
<Property name="rollingFileName">...</Property>
</Properties>
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="[%highlight{%-5level}] %d{DEFAULT} %c{1}.%M() - %msg%n%throwable{short.lineNumber}" />
</Console>
<RollingFile name="rollingFile" fileName="${logPath}/${rollingFileName}.log" filePattern="${logPath}/${rollingFileName}_%d{yyyy-MM-dd}.log">
<PatternLayout pattern="[%highlight{%-5level}] %d{DEFAULT} %c{1}.%M() - %msg%n%throwable{short.lineNumber}" />
<Policies>
<!-- Causes a rollover if the log file is older than the current JVM's start time -->
<OnStartupTriggeringPolicy />
<!-- Causes a rollover once the date/time pattern no longer applies to the active file -->
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.project" level="debug" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="rollingFile"/>
</Logger>
</Loggers>
</Configuration>
Actual results from current log file:
[[36mDEBUG[m] 2019-02-05 16:42:09,794 SpellCheck.getResult() - start
[[36mDEBUG[m] 2019-02-05 16:42:10,420 SpellCheck.getResult() - Spelling correction returned no results.
[[36mDEBUG[m] 2019-02-05 16:42:10,420 SpellCheck.getResult() - end
What I want to achieve:
[[36mDEBUG[m] 2019-02-05 16:42:09,794 SpellCheck.getResult() - 1234 - start
[[36mDEBUG[m] 2019-02-05 16:42:10,420 SpellCheck.getResult() - 1234 - Spelling correction returned no results.
[[36mDEBUG[m] 2019-02-05 16:42:10,420 SpellCheck.getResult() - 1234 - end
Where 1234 is for example the session id.
Thanks.
I figured it out, was a lot easier than I thought.
Basically added %X{userSessionId} to the
<PatternLayout pattern= ... />
row in log4j2.xml.
And in the code added
HttpSession session = request.getSession();
org.apache.logging.log4j.ThreadContext.put("userSessionId", session.getId());

log4net does not work in client pc

I've problem with log4net where it doesn't work in client pc but in my development pc it can create and write to the log file.
My VSTO add-in is using log4net (installed log4net package using NuGet). So inside my add-in ribbon code, I've added the following code :
Ribbon.vb
<Assembly: log4net.Config.XmlConfigurator(Watch:=True)>
<Runtime.InteropServices.ComVisible(True)> _
Public Class WordRibbon
Implements Office.IRibbonExtensibility
Private ribbon As Office.IRibbonUI
Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
......
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
</configSections>
<log4net>
<root>
<level value="ALL"/>
<appender-ref ref="RollingFileAppender"/>
</root>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="%envFolderPath{MyDocuments}\MyApp\AddInLog\WordAddin-log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="5MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
When I ran MS Word in my development PC (either debug from Visual Studio 2013 OR directly ran MS Word), log4net will be able to create the logfile inside MyDocuments folder.
But when I ran the add-in inside a clean virtual machine, there's no log file created. THere's no error prompted. Am I missing something here?
I found out the problems in vsto 4.0 sp1 will cause a VSTO Addin to not find its config file link.
Difference is in my case, the add-in can be loaded properly and it's working. It just the log4net somehow didn't work.
Before:
In the add-in registry, the Manifest value will be something like
Manifest="C:\Program Files\MyApp\WordAddIn.vsto|vstolocal"
After:
In the blog, the writer suggested for below changes.
Manifest="file:///C:/Program Files/MyApp/WordAddIn.vsto|vstolocal"
And I think that's the reason why log4net can work in my development pc, because Visual Studio use the same URI format for the Manifest value.
But for my case, I tried below and it can also work.
Manifest="C:\Program Files\MyApp/WordAddIn.vsto|vstolocal"
I use this URI because in my app, during installation the addin registry value path will be created based on users selection. If I want to change it to file:///, this will involved a few different files (not just the add-ins), so for now this is my solutions.
I'm not sure if using this format can cause any problem.

Why does debug output show in WinDbg but not VS2010?

We have .NET 4 application that does some logging.
When the application is launched from Studio, there's no output in the Debug view.
When the application is launched from WinDbg, the logging is shown as expected.
I've read that there was a change in .NET 4 preventing the logging from showing up in both Studio and WinDbg, but it doesn't seem to show up in Studio at all now. Before the solution was upgraded, it did log as expected in VS2008.
Why is the Debug output showing up correctly when launched from WinDbg but not when launched from VS2010?
This was due to a misconfigured log4net.config file.
Added the <appender> block and <appender-ref> block to reference said appender.
<log4net>
...
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]\r\n" />
<param name="Footer" value="[Footer]\r\n" />
<param name="ConversionPattern" value="%d [%t] %-5p %m%n" />
</layout>
</appender>
<root>
...
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>

NHibernate - see SQL without all the other guff

So I'm using log4net to write log output to the trace. Show sql is specified in the configuration file. I seem to have to set the log output level to DEBUG to get the SQL output, but DEBUG also produces pages and pages of other guff I have to scroll past.
Can I get the SQL without the guff?
Thanks
David
You can add a logger for NHibernate.SQL in the log4net config block, like so:
<logger name="NHibernate.SQL" additivity="false">
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
</logger>
With the appender-config
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date - %message%newline"/>
</layout>
</appender>
(replace this with whatever you prefer, like rollingFileAppender)
Another option is using a tool like NHibernate Profiler.