Wildfly doesn't recognize jboss deployment structure file - wildfly

I'm trying to configure Wildfly to use per deployment logging and jackson as provider for json on resteasy but looks like the AS doesn't recognize the file "jboss-deployment-structure.xml".
I wanna log the hibernate sql, i already put "<property name="hibernate.show_sql" value="true"/>" in persistence.xml.
And for Jackson, i use the following method:
#GET
#Path("/resumodia")
#Produces(MediaType.APPLICATION_JSON)
#Consumes("*/*")
#GZIP
public Response resumoHorariosDoDia() {
try {
final ResumoHorariosUsuarioDoDia resumoHorariosDoDia = geradorDeResumoHorarios.getResumoHorariosDoDia(new Date());
return Response.status(OK).entity(resumoHorariosDoDia).build();
} catch (Exception e) {
return Response.status(INTERNAL_SERVER_ERROR).entity("Erro ao processar a requisição: " + e.getMessage()).build();
}
}
The method works, but it ignores the json annotation i use on the object i return, like #JsonIgnore
The file is this one:
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
<module name="org.jboss.resteasy.resteasy-jettison-provider"/>
</exclusions>
<dependencies>
<module name="org.apache.log4j"/>
<module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
I put the file inside WEB-INF but it keeps using the wildfly logging and ignoring my log4j.xml.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM
"http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jakarta.apache.org/log4j/
http://jakarta.apache.org/log4j/ ">
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %5p [%-20c{1}] %m%n"/>
</layout>
</appender>
<category name="br.com.caelum">
<priority value="INFO"/>
<appender-ref ref="stdout"/>
</category>
<category name="org.hibernate">
<priority value="INFO"/>
<appender-ref ref="stdout"/>
</category>
<category name="org.hibernate.SQL">
<priority value="DEBUG"/>
<appender-ref ref="stdout"/>
</category>
<category name="org.jboss">
<priority value="INFO"/>
<appender-ref ref="stdout"/>
</category>
<category name="org.razor.cponto">
<priority value="INFO"/>
<appender-ref ref="stdout"/>
</category>
</log4j:configuration>
I'm using VRaptor 4

If you simply want to use per deployment logging, simply package your log4j.xml file with your deployment, there should be no need to mess about with deployment descriptors. What I do notice however is that your log4j config is trying to append to stdout rather than to an actual log file that is specific to this specific deployment, so it might well be actually using your new config, but then simply being merged into the main jboss logging due to lack of suitable appender

Related

How to enable logging DEBUG-level only for the Application Controllers'?

I'm on Scala 2.12.x Play 2.7.x and as part of my Application Controllers I'm using the logger like this (or equivalently by doing with play.api.Logging):
val logger = play.api.Logger(this.getClass)
and the configuration conf/logback.xml is shown below. The issue is that Application-Controllers' logger.debug(...) statements are not being output in the logs. I assumed that the application was set to DEBUG see one of the lasts entries <logger name="application" level="DEBUG" /> but there is obviously something wrong as the DEBUG statements are not being output?
<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${application.home:-.}/logs/application.log</file>
<encoder>
<pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern>
</encoder>
</appender>
<appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="STDOUT" />
</appender>
<logger name="play" level="INFO" />
<logger name="application" level="DEBUG" />
<logger name="slick" level="INFO" />
<logger name="slick.jdbc" level="DEBUG" />
<root level="WARN">
<appender-ref ref="ASYNCFILE" />
<appender-ref ref="ASYNCSTDOUT" />
</root>
</configuration>
PS: I know I can enable DEBUG for everything but then it is too much information I don't need, I'd like to see what's happening with my Controllers' logging.
The logger instantiated with play.api.Logger(this.getClass) inside a class like so
package controller
class HomeController extends ... {
val logger = play.api.Logger(this.getClass)
logger.debug("msg")
}
is not the application logger, but a distinct logger named
controller.HomeController
Thus to specify its log level add the following config to logback.xml
<logger name="controllers" level="DEBUG" />
This makes DEBUG the log level of all classes under controllers package.
Note application logger seems to be deprecated according to docs:
There is also a play.api.Logger singleton object that allows you to
access a logger named application, but its use is deprecated in Play
2.7.0 and above. You should declare your own logger instances...
If the messages are still not logging try changing from async appender to synchronous ones like so:
<root level="WARN">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>

Kubernetes log location inside the pod

I have a docker image for a Spring Boot app with the log file location as --logging.config=/conf/logs/logback.xml and the log file is as follows.
I am able to get the logs as
kubectl log POD_NAME
But, unable to find the log file when I log in to the pod. Is there any default location where the log file is placed as I haven't mentioned the logging location in the logback.xml file.
Logback file:
<?xml version="1.0" ?>
<configuration>
<property name="server.encoder.pattern"
value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %-5level : loggerName="%logger{36}" threadName="%thread" txnId="%X{txnId}" %msg%n" />
<property name="metrics.encoder.pattern"
value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %-5level : %msg%n" />
<!-- Enable LevelChangePropagator for jul-to-slf4j optimization -->
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator" />
<appender name="METRICS" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${metrics.encoder.pattern}</pattern>
</encoder>
</appender>
<logger name="appengAluminumMetricsLogger" additivity="false">
<appender-ref ref="METRICS" />
</logger>
<appender name="SERVER" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${server.encoder.pattern}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="SERVER" />
</root>
</configuration>
What you see from kubectl logs is console log from your service. Only console log can be seen like that and this is via docker logs support.

JBoss EAP 6.2 and Log4j2 stops writing logs after some time

I am using Log4j2 (RollingFile with routes) in my web application to log application specific logs in a few separate log files. The log4j2.xml file is bundled with in the WAR file.
Log files are generated and logs are generating fine to start with. After some time, it stops writing logs to the existing file and fails creating new folders/files too.
On restart everything resumes working and that is for some time only.
Tried monitoring, couldn't figure out any specific pattern or steps to simulate it.
<Configuration status="error" name="logger">
<Properties>
<Property name="logpath">path_to_log_file</Property>
</Properties>
<Appenders>
<Routing name="RoutingUserLogFile">
<Routes pattern="$${ctx:user}/">
<Route>
<RollingFile name="UserLogFile" fileName="${logpath}/${ctx:user}/MyLogFile.log" filePattern="${logpath}/${ctx:user}/%d{dd-MM-yyyy}-MyLogFile-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %-40C{1.} %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
<SizeBasedTriggeringPolicy size="4 MB" />
</Policies>
</RollingFile>
</Route>
</Routes>
</Routing>
</Appenders>
<Loggers>
<Root>
<level value="debug" />
<AppenderRef ref="RoutingUserLogFile" level="debug" />
</Root>
</Loggers>
</Configuration>

Chainsaw v2 SocketReceiver not working with log4j2 SocketAppender

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)

How in jboss write traces to separate trace file

How in JBoss to write traces to separate file?
I would like to see traces about org.hibernate.SQL and org.hibernate.type in separate trace file.
I added next appender and categories to jboss-log4j.xml but it does not help - jboss still writes traces into server.log.
<appender name="HIBERNATE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="/u1/trace/sql.log"/>
<param name="Append" value="true"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
</layout>
</appender>
<category name="org.hibernate.SQL">
<priority value="DEBUG"/>
<appender-ref ref="HIBERNATE" />
</category>
<category name="org.hibernate.type">
<priority value="TRACE"/>
<appender-ref ref="HIBERNATE" />
</category>
Adding appenders to a category is "additive" meaning that the new appender is logged to in addition to the existing root appender. You need to explicitly stop it from doing that:
<category name="org.hibernate.SQL">
<priority value="DEBUG"/>
<appender-ref ref="HIBERNATE" additivity="false"/>
</category>
The following setup works for me:
<category name="com.foobar.gearbox" additivity="false">
<priority value="DEBUG" />
<appender-ref ref="GB-FILE" />
</category>