log4j2 Socket Appender with SSL enabled - log4j2

Here is my log4j2 SocketAppender configured with SSL
<Configuration status="warn">
<Socket name="transSocketAppender" host="lxddv002.test.intranet"
port="9400" protocol="TCP" reconnectionDelayMillis="30000"
immediateFail="false">
<PatternLayout pattern="%m%n" charset="UTF-8" />
<SSL>
<Truststore location="C:\Users\AC26252\Desktop\certs\keystore.jks"
password="123456" />
</SSL>
</Socket>
<Async name="transSocketAsyncAppender" bufferSize="204800">
<AppenderRef ref="transSocketAppender" />
</Async>
I get this error on my server restart and the first few(2 or 3) request logs are lost and not being transported.
2018-11-22 19:04:05,243 AsyncAppender-socketAsyncAppender ERROR Unable to write to stream TLS:lxddv002.test.intranet:9400 for appender socketAppender: org.apache.logging.log4j.core.appender.AppenderLoggingException: Error writing to TLS:lxddv002.test.intranet:9400
2018-11-22 19:04:05,259 AsyncAppender-socketAsyncAppender ERROR An exception occurred processing Appender socketAppender
org.apache.logging.log4j.core.appender.AppenderLoggingException: Error writing to TLS:lxddv002.test.intranet:9400
at org.apache.logging.log4j.core.net.TcpSocketManager.write(TcpSocketManager.java:229)`at org.apache.logging.log4j.core.appender.OutputStreamManager.write(OutputStreamManager.java:201)`
Is there anything wrong with my configuration? Any help is appreciated. thanks

The issue was with my log4j2 version. I have upgraded to the latest version and its working fine now.

Related

Log4j2 logging level becomes different in Java 8 and Java 11

Log4j2 release 2.11.0 / 2.11.1 worked fine in Java 8 applications but not in Java 11
Here is an example of log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Properties>
<Property name="log-path">C:\\MyTestXXXX\\EnterpriseLogs</Property>
</Properties>
<Appenders>
<RollingFile name="MyTestOnly" fileName="${log-path}\ServerLog.log" filePattern="${log-path}\ServerLog_%d{yyyy-MM-dd}_%i.log" append="true">
<PatternLayout>
<Pattern>[#%d{HH:mm:ss}|%p|%m#]%n</Pattern>
</PatternLayout>
<Policies>
<CronTriggeringPolicy schedule="0 0 0 * * ?" evaluateOnStartup="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
<DefaultRolloverStrategy/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="OnlyLOG" additivity="true">
<AppenderRef ref="MyTestOnly" level="ALL" />
<Logger>
<Root level="ALL" />
</Loggers>
</Configuration>
In the Java source code, I did this:
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.core.Logger;
...
// Get org.apache.logging.log4j.core.Logger
Logger logger = (Logger) LogManager.getLogger("OnlyLOG");
logger.log(Level.forName("INFO", 600), "Log this text now!", new Exception("xxxxxx"));
Running in Java 8, I can see that serverLog.log has the content, which is good.
Running in Java 11, there is no log.
Through further study (debugging), I found this line interesting:
Logger logger = (Logger) LogManager.getLogger("OnlyLOG");
After execution, in Java 8, logger was something like "ALL in 2f333739", and log was fine.
But in Java 11, logger was something like "ERROR in 2f333739" and there was no log. Obviously the level became "ERROR" instead of "ALL".
So, I tries this in Java 11:
Level loggerLevel = logger.getLevel(); // Obviously it is ERROR level
logger.log(loggerLevel, "Log this text now!", new Exception("xxxxxx"));
The log happened in console (likely went through Root), not in the ServerLog.log that was configured in log4j2.xml for logger OnlyLOG.
So, what caused the level difference between Java 8 and Java 11? In other words, what should be modified so that in Java 11, log can still work the same way as in Java 8?
The issue is resolved. Here is the reason.
I used a new Eclipse IDE to run Java 11, when adding a project, I added lib folder to the class path, since log4j2.xml was in the lib folder. Now I inspected the IDE configuration a second time and found out that the lib folder was not in the class path. After a second attempt, the configuration is fine and logging becomes normal.
I made a second test by adding a brand new project into the Eclipse IDE. Interestingly enough, when adding lib folder to the class path, indeed I had to try twice, because the first time it was not added. By the way, the computer runs Windows 10. This did not happen when using a computer running in Windows 7.
Regardless, Log4j2 works fine in both Java 8 and Java 11.

Startup Error on Win10

Getting an error trying to start Neo4j on Windows 10:
Any thoughts from anywhere? Nothing in Operations Guide or Developers Guide talks about this DB. This is CE edition, running locally.
System log had this about the failure:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Windows Error Reporting" />
<EventID Qualifiers="0">1001</EventID>
<Level>4</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2017-03-08T15:40:28.976232300Z" />
<EventRecordID>14535</EventRecordID>
<Channel>Application</Channel>
<Computer>omitted</Computer>
<Security />
</System>
- <EventData>
<Data>129168941443</Data>
<Data>5</Data>
<Data>RADAR_PRE_LEAK_64</Data>
<Data>Not available</Data>
<Data>0</Data>
<Data>neo4j-ce.exe</Data>
<Data>0.0.0.0</Data>
<Data>10.0.14393.2.0.0</Data>
<Data>\\?\C:\Users\lschill\AppData\Local\Temp\RDRB4ED.tmp\empty.txt \\? \C:\ProgramData\Microsoft\Windows\WER\Temp\WERB50E.tmp.WERInternalMetadata.xml</Data>
<Data>0</Data>
<Data>8d3dd2f1-0415-11e7-96b5-d481d7785562</Data>
<Data>0</Data>
<Data>79b1c284dc68f120300f3bcf10cd53ef</Data>
</EventData>
</Event>
AppData and ProgramData files referenced did not exist when I looked.
It appears that this error appears when you do not have installed JAVA 8 server JRE on your computer

TSung HTTP not working with header

We are performing load testing using tsung.
We were able to load test a HTTP end point without any headers.
But when add HTTP header, tsung is failing and not able to make the request.
I am unable to decipher from the tsung logs the issue. The format of the configuration tsung.xml is exactly as per the tsung help docs.
please find the below tsung.xml configuration we used and also error from logs,
tsung.xml
<sessions>
<session name="http-example" probability="100" type="ts_http">
<request>
<http url="http://172.17.0.1/api/test" version="1.1" method="GET">
<http_header name="Authorization" value="Bearer a3b84dd8-d8a3-4e37-9468-5244333df0e0"/>
</http>
</request>
</session>
</sessions>
tsungcontroller.log
** Reason for termination =
** {{case_clause,false},
[{ts_http_common,'-headers/1-fun-0-',2,
[{file,"src/tsung/ts_http_common.erl"},{line,224}]},
{lists,foldl,3,[{file,"lists.erl"},{line,1248}]},
{ts_http_common,http_no_body,2,
[{file,"src/tsung/ts_http_common.erl"},{line,75}]},
{ts_http,get_message,2,[{file,"src/tsung/ts_http.erl"},{line,130}]},
{ts_client,handle_next_request,2,
[{file,"src/tsung/ts_client.erl"},{line,798}]},
{gen_fsm,handle_msg,7,[{file,"gen_fsm.erl"},{line,505}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}
Please let me know what I am missing
I was using tsung 1.5.1 earlier. But the issue is resolved in 1.6 :) :)
I am able to add http headers.

Spring websocket set handshake handler/interceptor

I try to set handshake handler through xml config:
<bean id="customHandler" class="app.wsock.CustomHandler"/>
<websocket:message-broker>
<websocket:stomp-endpoint path="/foo">
<websocket:handshake-handler ref="customHandler"/>
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:stomp-broker-relay prefix="/topic,/queue" />
</websocket:message-broker>
but on connect also using DefaultHandshakeHandler. What I'm doing wrong?
This is a bug (see SPR-11568).
You'll need to update your app to Spring Framework 4.0.3.

Struts2 with SLF4J and Logback produces double logs

I have a very weird problem with Struts 2.1.8 and SLF4J with Logback. I think I have setup everything as it should be (logback-core, logback-classic, slf4j-api and removed commons-logging from Struts JARs), but the logs look like this:
16:23:59,985 INFO [stdout] (ajp-localhost-127.0.0.1-8009-3) 2013-05-11 16:23:59,985 DEBUG [BasicTilesContainer.java:615] [ODk3Cc2-mn-X8eVfnemQn5WZ.undefined] - Render request recieved for definition 'DocumentList'
Clearly there are two timestamps, and one logging framework is logging through another somewhere, which causes this problem.
JBoss 7.1.1 is used.
Any ideas how to solve this problem?
EDITED:
This is how Logback configuration looks like:
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %5p [%F:%L] [%X{sessionId}] - %m%n</pattern>
</encoder>
</appender>
I had a problem with modules in JBoss 7, but now although they are solved and Logback is really loaded, but the log files still are a mess. They look like if they are logged through JUL:
20:23:46,128 INFO [stdout] (connector_xxxx) 2013-05-11 20:23:46,127 DEBUG [ReConnector.java:83] [] - Next connection attempt in (ms) 20000
It looks like one logger is logging through the other.

Resources