How do I get log4net console output to show up when using TestDriven.net to run nunit tests? I'm using the ColoredConsoleAppender, and there is no log output.
I've found the answer. You can use the regular xml config file approach, but you need to configure a TraceAppender:
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %logger - %message%newline" />
</layout>
</appender>
Related
I am using logback.xml for logging. I want to disable the logs from 3rd party jars/SDKs. For this I used the log level="OFF" for that jar, but still the logs are getting logged. Next I tried using the same log level for one of my files in codebase, I was able to disable the logs for my file.
Below is my logback config :
'''
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern> Some pattern </pattern>
</encoder>
</appender>
<logger name="<sdk file path>" level="OFF"/> !--- This doesn't work ---!
<logger name="<file from my codebase>" level="OFF"/> !--- This works ---!
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
'''
A library can use any name it likes for a logger so the name will not necessarily match the path of the library.
The %logger field in the pattern gives the name of the logger so you will see the actual name in the logging output. If you see output that you want to suppress, use the name from the log (or a prefix) in the logger element.
I would also recommend setting the root to the lowest level and then increasing the level for the specific libraries that you are interested in.
<logger name="myloggername" level="DEBUG"/>
<root level="ERROR">
<appender-ref ref="STDOUT"/>
</root>
I have reviewed other related questions but have not found a answer for this. It seems the javadocs at https://logging.apache.org/log4j/extras/apidocs/org/apache/log4j/rolling/RollingFileAppender.html are incorrect and/or incomplete. At least the element looks to have a spurious double quote mark in it.
I am starting up in debug mode and it all looks OK. Yet, I cannot find the log file. We have other custom appenders that are working fine but I am trying to replace them with the OTB solution.
Here is my config:
<appender name="file" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="threshold" value="debug" />
<rollingPolicy name="file" class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="logs/My_Server.%d{yyyy-MM-dd-hh}.log"/>
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %r [%t] %-5p %c{1} %x - %m%n"/>
</layout>
</appender>
<appender name="ASYNCfile" class="org.apache.log4j.AsyncAppender">
<param name="BufferSize" value="500"/>
<param name="blocking" value="false"/>
<appender-ref ref="file"/>
</appender>
<root>
<priority value="INFO"/>
<appender-ref ref="ASYNCfile"/>
<appender-ref ref="console"/>
</root>
And the debug console:
log4j: Attaching appender named [file] to appender named [ASYNCfile].
log4j: Class name: [org.apache.log4j.rolling.RollingFileAppender]
log4j: Setting property [threshold] to [DEBUG].
log4j: Setting property [fileNamePattern] to [logs/My_Server.%d{yyyy-MM-dd-hh}.log].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{ISO8601} %r [%t] %-5p %c{1} %x - %m%n].
log4j: setFile called: logs/My_Server.2017-07-17-05.log, true
log4j: setFile ended
I don't see any errors related to this in the console ouput - there is just no file to be found.
I'm new to logback and I'm trying to stop a SiftingAppender programmatically.
Here is my appender:
<appender name="FILE-APPENDER" class="ch.qos.logback.classic.sift.SiftingAppender">
<!-- MDC value -->
<discriminator>
<key>fileName</key>
<defaultValue>log_file</defaultValue>
</discriminator>
<sift>
<appender name="ROLLING-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<append>true</append>
<file>{fileName}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- daily rollover. Make sure the path matches the one in the file element or else
the rollover logs are placed in the working directory. -->
<fileNamePattern>${fileName}-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>1MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>[%p] [%d{yy/MM/dd HH:mm:ss}] %c [%X{akkaSource}] : %msg%n</pattern>
</encoder>
</appender>
</sift>
</appender>
Root Logger:
<root level="INFO">
<appender-ref ref="FILE-APPENDER"/>
<appender-ref ref="ANOTHER-APPENDER"/>
</root>
At some point in the application I need to stop logging to file, here is my scala code:
val context: LoggerContext = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]
val root = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME).asInstanceOf[Logger]
root.getAppender("FILE-APPENDER").stop()
The code gets executed with no problem, but I still can see logs in the file.
If I don't use SiftingAppender and instead use only RollingFileAppender it works perfectly.
Is there anything that I'm missing here?
I'm using Log4J for logging in SBT. In a configuration file, I've defined the TRACE level for the root node. When I run the project (sbt run) all debug output is displayed correctly. But when I run the tests (sbt test), no output at all is generated. I need to insert the class into the configuration to see the output.
The test are written in a JUnit style. Executing the tests with Eclipse shows all Log4J Output. So, it seems to be an issue with SBT or scalatest.
Log4J Configuration:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false" xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%-5r [%-5p] %c: %M - %m%n"/>
</layout>
</appender>
<appender name="asyncApp" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="fileApp"/>
</appender>
<appender name="fileApp" class="org.apache.log4j.FileAppender">
<param name="File" value="testlog_Compiler"/>
<param name="Append" value="true" />
<param name="Threshold" value="ALL"/>
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%d [%-5p] %c: %M - %m%n"/>
</layout>
</appender>
<appender name="fileAppTest" class="org.apache.log4j.FileAppender">
<param name="File" value="testlog_Tests"/>
<param name="Append" value="true" />
<param name="Threshold" value="ALL"/>
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%d [%-5p] %c: %M - %m%n"/>
</layout>
</appender>
<logger name="main.Main$" additivity="true">
<level value="INFO" />
</logger>
<!--
<logger name="compile.Compiler" additivity="true">
<level value="DEBUG" />
</logger>
-->
<logger name="test" additivity="false">
<level value="TRACE" />
<appender-ref ref="stdout"/>
<appender-ref ref="fileAppTest"/>
</logger>
<root>
<priority value="TRACE"/>
<appender-ref ref="asyncApp"/>
<appender-ref ref="stdout"/>
</root>
</log4j:configuration>
When I use this version of the config file, the tests of compile.Compiler don't generate any log output unless I uncomment its node in the Log4J config. In the SBT configuration file, these dependencies are defined for compile.Compiler: (This is just a minimal example.)
class Comp2011ParentProject(info: ProjectInfo) extends DefaultProject(info) {
val compiler = project("compile", "compile", new Compile(_))
class compiler(info: ProjectInfo) extends DefaultProject(info) with Eclipsify {
val scalatest = "org.scalatest" % "scalatest_2.9.0" % "1.6.1"
val junitInterface = "com.novocode" % "junit-interface" % "0.6" % "test->default"
val log4j = "log4j" % "log4j" % "1.2.16"
val log4jExtras = "log4j" % "apache-log4j-extras" % "1.1"
}
}
Does anyone have a clue why this happens and how to stop it?
(Unfortunately I lost my account which posted this question. :-( But this is also some kind of answer.)
Further investigations showed that at some point in code the level for the compile.Compiler logger was manually set to INFO. When I delete this statement, everything works fine.
The surprising fact about this is that setting the level in one test also causes all the following tests to adopt that logging level. This was hard to understand because I thought the configuration file was reloaded with every new test.
However, after some documentation surfing, I found out that the actual configuration is not reset when loading a configuration file. To have this behavior a BasicConfigurator.resetConfiguration() must be executed before loading the configuration. With this, everything works as expected.
I already have log file. Now what i need is to make the graph of that log file.
Is there any command line tool or google API to make graph which will show every transaction time.
Thank You
You can upload your file to Google Docs as a spreadsheet and then do charting & graphs out of it.
I use something like this:
java -jar perf4j-0.9.13.jar /path/to/perf4jLog.log -t 86400000 -g out.html
Note here where i use -t 86400000 which means collate the data via days. Use whatever is applicable for you.
My log4j.xml looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="perf4jLog" class="org.apache.log4j.DailyRollingFileAppender">
<param value="perf4jLog.log" name="File"/>
<param value="'.'yyyy-MM-dd" name="DatePattern"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<logger name="org.perf4j.TimingLogger">
<level value="INFO"/>
<appender-ref ref="perf4jLog"/>
</logger>
<root>
<priority value ="INFO"/>
</root>
</log4j:configuration>
Now you can open up out.html and the images should load the chart from google.