I have a weird problem where for a single application, JBoss (EAP 6.0.0) seems to be dumping access logs in my home dir at ~/logs. This is annoying to say the least.
My web application's jboss-web.xml file seems normal:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">
<jboss-web>
<context-root>/moore</context-root>
<!-- http://tomcat.apache.org/tomcat-5.5-doc/config/valve.html#Access_Log_Valve -->
<valve>
<class-name>org.apache.catalina.valves.AccessLogValve</class-name>
<param>
<param-name>prefix</param-name>
<param-value>access_log_moore_</param-value>
</param>
<param>
<param-name>suffix</param-name>
<param-value>.log</param-value>
</param>
<param>
<param-name>pattern</param-name>
<param-value>%h %A %l %u %t "%r" %s %b %T %I "%{Referer}i" "%{User-Agent}i"</param-value>
</param>
<param>
<param-name>resolveHosts</param-name>
<param-value>false</param-value>
</param>
<param>
<param-name>fileDateFormat</param-name>
<param-value>yyyy-MM-dd-HH</param-value>
</param>
</valve>
</jboss-web>
I can't seem to find anywhere that's telling it to dump logs in ~/logs and all other web applications log fine to the JBoss log directory. How can I debug where the misconfiguration is and get these logs back to the JBoss log directory?
I think the best approach to configure access logs in JBoss EAP 6.x is add this in domain:web subsystem.
Eg:
<subsystem xmlns="urn:jboss:domain:web:1.4" default-virtual-server="default-host" native="false">
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<virtual-server name="default-host" enable-welcome-root="true">
<alias name="localhost"/>
<alias name="example.com"/>
<access-log pattern="%h %A %l %u %t "%r" %s %b %T %I "%{Referer}i" "%{User-Agent}i"" prefix="access_log_moore_" rotate="true">
<directory path="." relative-to="jboss.server.log.dir" />
</access-log>
</virtual-server>
</subsystem>
See also: JBoss EAP 6.0.1 Model Reference
However if you need/want use a valve configuration inside application with jboss-web.xml you must add attribute directory in your configuration with absolute path to log directory.
Eg:
<jboss-web>
<context-root>/moore</context-root>
<valve>
<!-- ... -->
<param>
<param-name>directory</param-name>
<param-value>/path/to/jboss/log/dir</param-value>
</param>
</valve>
</jboss-web>
directory
Absolute or relative pathname of a directory in which log files
created by this valve will be placed. If a relative path is specified,
it is interpreted as relative to $CATALINA_HOME. If no directory
attribute is specified, the default value is "logs" (relative to
$CATALINA_HOME).
In JBoss 7/EAP 6 $CATALINA_HOME is not set and the log is created in ~/logs (In your case).
Ref: https://docs.jboss.org/jbossweb/latest/config/valve.html
I hope this help.
Related
I am running a Log4J2 TCPSocketServer on an edge node in a cluster. All the data nodes send log events to the TCPSocketServer on the edge node and also log locally in the data node using the log4j2.xml configuration file as shown below. The Application Name is stored as a System property and is accessible in the data node or client's log4j2.xml configuration using ${sys:ABC.appname}. How can I send the same appname to the edge node where TCPSocketServer is running using the log4j2.xml. I would be using the same Application Name in the log4j2-server.xml to log events into separate log files just like I am doing locally on data node.
Sample snippet from data node or Client - log4j2.xml :
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" >
<Appenders>
<Socket name="socket" host="localhost" port="12345" >
<SerializedLayout />
</Socket>
<File name="MyFile" fileName="/var/log/${sys:ABC.appname}.log" >
<PatternLayout>
<Pattern>%d{ISO8601} %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="socket"/>
<AppenderRef ref="MyFile"/>
</Root>
</Loggers>
</Configuration>
Sample snippet from edge node or Server - log4j2-server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<File name="MyFile" fileName="/var/log/data/${hostName}-<**This is where I would like to see the appname from data node**>.log" >
<PatternLayout>
<Pattern>%d{ISO8601} %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
<Async name="AsyncFile">
<AppenderRef ref="MyFile" />
</Async>
</Appenders>
<Loggers>
<Root level="WARN">
<AppenderRef ref="AsyncFile"/>
</Root>
</Loggers>
</Configuration>
I used ThreadContext to resolve this issue. Its pretty easy to add Thread Context into the codebase and later use Routing to segregate the log events based on the ThreadContext. I followed the example on this link to do the same https://logging.apache.org/log4j/2.x/faq.html#separate_log_files
I'm trying to use Chainsaw v2 from http://people.apache.org/~sdeboy
I don't want to use zero configuration. Just a simple socketAppender/SocketReceiver combo.
I'm using log4j2 with the following configuration
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" >
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<Socket name="SharathZeroConf" host="localhost" port="4445">
</Socket>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="SharathZeroConf" />
<AppenderRef ref="CONSOLE" />
</Root>
</Loggers>
</Configuration>
On ChainSaw, I'm selecting the option "Receive events from network" with port 4445.
However chainsaw doesnt log anything.
I've verified that the appender configuration is correct on log4j side by using the builtin socketserver
java -cp ~/.m2/reposiry/org/apache/logging/log4j/log4j-api/2.0.2/log4j-api-2.0.2.jar org.apache.logging.log4j.core.net.server.TcpSocketServer 4445
So the bug must be on chainsaw side. Any pointers #Scott ?
You're right, I got the same issue. I just tried with LogMX instead, and it works like a charm:
I just had to copy Log4j JARs in LogMX lib/ directory (i.e. log4j-api-2.xx.jar and log4j-core-2.xx.jar)
I am relatively new to JBOSS. I have to use a custom appender of which I have a jar file available.
For eg.
<appender name="MYLOGGER" class="org.log4j.appender.MyLogAppender">
<param name="File" value="/logs/abc.log"/>
<param name="Threshold" value="DEBUG"/>
...more parameters...
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %-23d{} [%t] %x: %c{1} - %m%n"/>
</layout>
</appender>
But doing so I get the error
log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassNotFoundException: org.log4j.appender.MyLogAppender
Which file other than jboss-log4j.xml must be configured ?
Where must the jar file be placed in the jboss hierarchy and how must the jboss-log4j.xml be configured to use the appender ?
Thanks.
You don't say which version of JBoss that you're using, but for JBoss 5.1.0, Log4J lives in $JBOSS_HOME/common/lib, so I'd suggest putting your jar file there.
I need to use log4j to append logs to a socket with UDP. However, I cannot find much on the internet about how to do so. In Log4J, the socketappender uses TCP. So I got log4j 2 beta, but I can't find any examples/documentation on how to use the socketappender, especially for UDP. I would really appreciate it if anyone could give me an example/show me how to use Log4j for UDP. Thanks.
I have been working with log4j 2.0-beta8 and got the UDP appender working with following log4j2.xml file (but note the 2 in the name of the file!):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appenders>
<Socket name="UDP" host="myhostname.com" port="3333" protocol="UDP">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1} - %m%n"/>
</Socket>
</appenders>
<loggers>
<root level="info">
<appender-ref ref="UDP"/>
</root>
</loggers>
</configuration>
I am using JBoss 6.0 .
I have deployed my web application: myApp.ear under the web-context: "/test".
So in browser-url if I type "http://localhost:8080/test/", I do get my login page (myLogin.jsp).
Since my WAR exists inside a EAR file, I have specified the context root in the application.xml file using a context-root element inside of the web module - i.e.
<module>
<web>
<web-uri>myWeb.war</web-uri>
<context-root>/test</context-root>
</web>
</module>
My question is how to auto direct user to my web-app from "root context"?
I mean if user types "http://localhost:8080/", I would expect my web-application's login page to load (instead of JBoss's default ROOT.war's index.html page).
I deleted existing index.html from {JBOSS}\server\default\deploy\ROOT.war and created a login.jsp there. Now I can see that "login.jsp" is getting invoked when I type http://localhost:8080/. But I can not redirect user-request to my web-app's login page.
In that login.jsp, I have tried with:
<jsp:forward page="/test" />, but I get error: "HTTP Status 404 - /test".
If I invoke like <jsp:forward page="/test/myLogin.jsp" /> I still get the same 404 error.
Can any one suggest how to achieve the auto-direct to my web-app from root-context?
You need to keep index.html in default deploy folder and forward request to your web module.
For example keep following line only in index.html
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=/test/"/>
The answer from Senthil works nice, but user could see the actual redirect done by the browser (page blinks). The redirect can be done also with rewrite [1, 2] functionality of the JBoss server, which supports HTTP Redirect with 30x codes (no blink).
You can either add the rewrite to your app directly (web.xml, jboss-web.xml) and specify the redirect rules in rewrite.properties - not shown here.
Or you can modify the server configuration on it's own without touching the original application. I find this solution handy because the application is left intact.
Use case: We use this for EJBCA deployment (not our app), it sets it's context root to /ejbca. We want to preserve the default deployment process provided by the packaged ant script while in the same time we would like to add a redirect from / to /ejbca as some kind of default, for user friendliness. If user wants to change it, it's done simply by modifying standalone.xml without need to redeploy the whole app.
Edit standalone.xml:
<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
<virtual-server name="default-host" enable-welcome-root="true">
<alias name="localhost"/>
<rewrite pattern="^/$" substitution="/test" flags="L,QSA,R" />
</virtual-server>
</subsystem>
This has worked for me on Wildfly 26.1.1 and JBoss EAP 7.4.
<subsystem xmlns="urn:jboss:domain:undertow:12.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other" statistics-enabled="${wildfly.undertow.statistics-enabled:${wildfly.statistics-enabled:false}}">
<buffer-cache name="default"/>
<filters>
<rewrite name="myfilter" redirect="true" target="/myapp/"/>
</filters>
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
<https-listener name="https" socket-binding="https" ssl-context="applicationSSC" enable-http2="true"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<http-invoker http-authentication-factory="application-http-authentication"/>
<filter-ref name="myfilter" predicate="path('/')"/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<application-security-domains>
<application-security-domain name="other" security-domain="ApplicationDomain"/>
</application-security-domains>
</subsystem>
It looks like much but actually is not. My solution shows the default configuration, I just had to add the <filters> section and the <filter-ref>.
Be aware the <filters> section must come above <server> otherwise JBoss will complain at startup. This was not documented at https://access.redhat.com/solutions/2996371 but after all I found https://docs.wildfly.org/19/wildscribe/subsystem/undertow/index.html.
In jboss-cli this means:
/subsystem=undertow/configuration=filter/rewrite=myfilter/:add(redirect=true, target=/myapp)
/subsystem=undertow/server=default-server/host=default-host/filter-ref=myfilter/:add(predicate="path('/')")
The automatically generated standalone.xml does not have exactly the same structure as above but works as well.