log4j2 highlight first line only in the console - eclipse

I am using log4j2 to log to the console and file as in this xml file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - Line %L: %msg%n}"/>
</Console>
<File name="MyFile" fileName="all.log" immediateFlush="true" append="false">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - Line %L: %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" level="error"/>
<AppenderRef ref="MyFile" level="info"/>
</Root>
</Loggers>
</Configuration>
The problem is only the first line in the netbeans console appears in red while the remaining lines are black as in the following picture.
Any help will be appreciated
Update:I tried the project with eclipse and all lines appeared in black

Related

Log4j - Log file not getting sent to external log viewer

I have a pod that uses a log4j2.xml config file to manage logging configuration and for sending it to an external log viewer (Elastic Search). This pod has two log files that need to sent to Elastic Search. A main log file and a ruletrace log file. This is the log4j config file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="30">
<Properties>
<Property name="logFolder">/var/log/svc</Property> <!-- Must NOT end with a slash -->
</Properties>
<appenders>
<Console name="console" target="SYSTEM_ERR">
<PatternLayout pattern="%d{ISO8601};%p;[%t];%logger;%msg\n"/>
</Console>
<RollingRandomAccessFile name="allLogRollingFileAppender"
fileName="${logFolder}/svc.log"
filePattern="${logFolder}/svc-%d{yyyy-MM-dd}T%d{HH-mm}_%i.log.gz"
immediateFlush="false">
<PatternLayout pattern="%d{ISO8601};%p;[%t];%logger;%msg\n"/>
<Policies>
<CronTriggeringPolicy schedule="0 0 0 * * ?"/>
<SizeBasedTriggeringPolicy size="20 MB" />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${logFolder}" maxDepth="1">
<IfFileName glob="svc-*.gz">
<IfAccumulatedFileSize exceeds="100 MB" />
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="ruleTraceRollingFileAppender"
fileName="${logFolder}/svc_ruletrace.log"
filePattern="${logFolder}/svc_ruletrace-%d{yyyy-MM-dd}T%d{HH-mm}_%i.log.gz"
immediateFlush="true">
<PatternLayout pattern="%m%n"/>
<Policies>
<CronTriggeringPolicy schedule="0 0 0 * * ?"/>
<SizeBasedTriggeringPolicy size="30 MB" />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${logFolder}" maxDepth="1">
<IfFileName glob="svc_ruletrace*.gz">
<IfAccumulatedFileSize exceeds="100 MB" />
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
<Syslog name="sysLogAppender"
format="RFC5424"
advertise="false"
host="localhost"
port="5140"
protocol="UDP"
facility="local6"
appName="svc"
enterpriseNumber="193"
mdcId="svcMdcId"
includeMDC="false"
newLine="true"
exceptionPattern="%throwable{full}"
immediateFlush="false">
<MarkerFilter marker="RULETRACE" onMatch="DENY" onMismatch="ACCEPT"/>
</Syslog>
</appenders>
<loggers>
<Logger name="RuleTrace" level="debug" includeLocation="false" additivity="false">
<AppenderRef ref="ruleTraceRollingFileAppender"/>
</Logger>
<Logger name="com.comp" level="info" additivity="true">
<AppenderRef ref="allLogRollingFileAppender"/>
</Logger>
<root level="info">
<AppenderRef ref="console" level="fatal"/>
<AppenderRef ref="sysLogAppender" level="info"/>
</root>
</loggers>
</Configuration>
The main log file (svc.log) gets sent to ElasticSearch with no issues. The ruletrace doesn't, however. There are log messages appearing in the ruletrace log file on the pod but those log messages don't get sent to ElasticSearch. I've tried changing the settings below a few times to different configs but it makes no difference, seemingly.
Is there a limit to the amount of Loggers you can reference? Would the difference in pattern layout make a difference?

RollingFile Appender not using current date

The Rolling File Appender is not putting the most recent log entries in the current date file.
In the log4j2.xml file I have a RollingFile appender which looks like this
<RollingFile
name="viewAppender"
filePattern="/data/view/view%d{yyyy-MM-dd}.log">
<PatternLayout><pattern>%m%n</pattern></PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
</Policies>
</RollingFile>
When the new log entry goes, its not going in the current date
Here is the log file. It shows that the most recent entry was from Aug 30 but the log file name was for Aug 28. It should have created a new log file with filePattern view2018-08-30.log
-rw-r--r-- 1 root root 230 Aug 30 10:36 view2018-08-28.log
You can use below log4j2.xml which is a working one and creates new log file everyday
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="60">
<Appenders>
<Console name="console-appender" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} -
%msg%n"/>
</Console>
<RollingFile name="rollingFile-appender"
fileName="${sys:user.home}/log/apache-tomcat/file.log"
filePattern="${sys:user.home}/log/apache-tomcat/file-%d{yyyy-MM-dd}.log">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} -
%msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="50MB"/>
</Policies>
<DefaultRolloverStrategy max="30"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="rollingFile-appender"/>
<AppenderRef ref="console-appender"/>
</Root>
</Loggers>
</Configuration>

Using logback with Akka

I have some problems using Logback with my Akka (2.3.9) application. In order to log to stdout and in the logfile, I specified the logback.xml with all appenders:
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds" debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder>
<pattern>%X{akkaTimestamp} %-5level %logger{36} %X{sourceThread} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./akka.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>./akka.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%X{akkaTimestamp} %-5level %logger{36} %X{sourceThread} - %msg%n</pattern>
</encoder>
</appender>
<logger name="proc" level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</logger>
<logger name="akka.actor" level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</logger>
<root level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</root>
</configuration>
After that I use logging in my Actor:
val log = Logging(context.system, classOf[MyActor])
override def receive: Receive = {
case MyEvent(event) =>
log.info("Message received for processing.")
}
The problem is, in SBT everything is fine: I can see all log events in the created logfile.
When I make JAR-File with sbt-assembly and start this jar file (java -jar event-assembly-0.1.1-SNAPSHOT.jar). The app writes log entries to STDOUT but not in the file!
I have no idea how I can fix that. I tried with "lsof", the java process has no open log-files.
I don't know what's wrong but you could do the following:
Check if your logback.xml is in the jar-file
Try to start your application with java -Dlogback.configurationFile=/path/to/logback.xml -jar event-assembly-0.1.1-SNAPSHOT.jar
So, how I found out, the sbt-assembly removed some logback-binaries from the result jar (it was settings in my Build.scala). After I changed the MergingStrategy to preserve the first logback occurrence in the result build, all works correctly.

Limiting length of ENSIME server buffer; hook for this buffer

I want to limit the length of the *inferior-ensime-server-...* buffer to a few thousand lines.
This looks promising, from https://stackoverflow.com/a/11255400/1007926, but does not work in this case:
(add-hook 'compilation-filter-hook 'comint-truncate-buffer)
(setq comint-buffer-maximum-size 2000)
Is there an ENSIME server buffer hook that I can use in place of 'compilation-filter-hook?
Maybe these hooks can be used to truncate the buffer occasionally:
https://github.com/ensime/ensime-emacs/blob/master/ensime-mode.el
you can always supply your own logback.xml file by customising ensime-server-logback and then doing your own filtering.
https://github.com/ensime/ensime-emacs/blob/aafff027f40ea58e22538272edd0a5b676821978/ensime-vars.el#L85
It worked for me, I did a M-x customize-group ensime-server and then, in ensime-server-logback I had to set the path to the logback.xml as a string: "/home/user/.sbt/0.13/plugins/logback.xml". This is my logback:
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="file" class="ch.qos.logback.core.FileAppender">
<file>it.log</file>
<append>false</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %X{akkaSource} %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="WARN">
<appender-ref ref="file" />
</root>
<logger name="org.ensime" level="WARN" />
<logger name="akka" level="WARN" />
</configuration>

Will this log4j configuration file create application.log files appended with the timestamp?

I have a log4j configuration file that looks like:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/' debug="false">
<appender name="consoleAppender"
class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="INFO" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d
%-5p [%c{1}] %m %n" />
</layout>
</appender>
<appender name="fileAppender"
class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="INFO" />
<param name="File" value="/var/output/logs/application.log"/>
<param name="DatePattern" value=".yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MMM-dd HH:mm:ss,SSS} [%t] %c %x%n %-5p %m%n"/>
</layout>
</appender>
<logger name="connect.testJava" additivity="false" >
<level value="DEBUG" />
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileAppender"/>
</logger>
</log4j:configuration>
I wanted to basically create logs with the format application.log like application2013-06-12 12:12:00.log or something like that. The above configuration does not seem to be doing that. Can someone please help me out and tell me what I might be doing wrong? I am just about a couple of hours into log4j, so sorry if this question sounds too naive.
Yes it does. Just wait till midnight and a new file will be created. The day's file will remain application.log