Debug Gatling Scala Code in Intellij with Maven Java Project - scala

I didn't add a comment in this Debug Scala Post because in my opinion it was another setup.
I had a similiar problem with Maven instead of SBT. I used Maven because the complete Java project was built upon it and I only wanted to debug my Gatling Scala code. However I'm not able to debug the code with the IDE.
Here's what I tried:
Clean the built mvn clean install
Invalidate caches in IDEA with the menu button
Use println to see whether the code is reached - worked
Redeploy the project on the Glassfish
Delete the generated files in the Glassfish and redeploy
This is my current setup:
Maven 3.3.9
Glassfish Payara 4 build 163
IDEA 2016.3.4. built on January 31 2017
JDK 1.8.0_51
Gatling 2.2.3
Scala-Maven-Plug 3.2.2
My solution is as follows.

With the help of colleague I figured out that the main class in Engine from the Gatling tutorial can be used to debug out of Intellij.
I basically built the whole archetype and moved the following files into the corresponding folders:
src/test/resources/gatling.conf
src/test/scala/Engine.scala and IDEPathHelper
That did the trick for me.

If anybody is finding hard to this just create a logback.xml file under src/test/resources and mention the following according to your need:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
<immediateFlush>false</immediateFlush>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>../gatling.log</file>
<append>true</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
</encoder>
</appender>
<!-- Uncomment for logging ALL HTTP request and responses -->
<!-- <logger name="io.gatling.http.ahc" level="TRACE" /> -->
<!-- <logger name="io.gatling.http.response" level="TRACE" /> -->
<!-- Uncomment for logging ONLY FAILED HTTP request and responses -->
<logger name="io.gatling.http.ahc" level="DEBUG" />
<logger name="io.gatling.http.response" level="DEBUG" />
<root level="WARN">
<appender-ref ref="CONSOLE" />
</root>
<root level="WARN">
<appender-ref ref="FILE" />
</root>
</configuration>

Related

Play framework (2.3.7) not using my logback configuration

I am using Play 2.3.7
I read the documentation here
https://www.playframework.com/documentation/2.3.x/SettingsLogger
I created a file called application-logger.xml (and as logger.xml) under my conf directory
<configuration>
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${application.home}/logs/foo.log</file>
<encoder>
<pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
</encoder>
</appender>
<logger name="play" level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</logger>
<logger name="application" level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</logger>
<root level="off" />
</configuration>
Now I run my play application activator clean run and it prints nothing on the console if there is an error. there is no file 'foo.log' created as well.
Based on my reading of the documentation, I thought all my application code will use a logger called "application" and the play internal would use a logger called "play" so if I define appenders for these two loggers I will have everything on console and my file.
But that does not seem to be happening.
I have put the application-logger.xml file in conf directory next to application.conf file.
I also tried renaming my file to logger.xml but still it is just ignored.
Edit::
I even tried to run my application like
./activator -Dlogger.resource=logger.xml run
./activator -Dlogger.file=./conf/logger.xml run
But nothing can make the play framework pick up that file. nothing.
I was able to find a solution here
https://www.reddit.com/r/scala/comments/6q6vb3/why_is_it_such_a_big_deal_for_play_framework_to/
Basically when launching the app use the logback configuration setting
so activator -Dlogback.configurationFile=logger.xml run`
The play documentation setting -Dlogger.resource or -Dlogger.file does not work.
This can be the case with custom ApplicationLoader, it require update load with
LoggerConfigurator(context.environment.classLoader).foreach {
_.configure(context.environment, context.initialConfiguration, Map.empty)
}
https://www.playframework.com/documentation/2.6.x/SettingsLogger#Using-a-custom-application-loader
I run it from IntelliJ, and with
-Dlogger.resource=logback-test.xml works smoothly.

Spring boot and JBoss 8 Wildfly log configuration application

I have a Spring boot application prepare to be a WAR. It deploys without problems on Tomcat 8 (embedded or standalone) as well as on JBoss 8 Wildfly.
But while on Tomcat we have had configured working logback configuration on JBoos it does not work any more.
I have tried few different suggested solutions:
https://stackoverflow.com/a/21887529/3997870
https://stackoverflow.com/a/23080264/3997870
The best which I have found was to add to my project WEB-INF/jboss-deployment-structure.xml with
<jboss-deployment-structure>
<deployment>
<!-- exclude-subsystem prevents a subsystems deployment unit processors running on a deployment -->
<!-- which gives basically the same effect as removing the subsystem, but it only affects single deployment -->
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
but still it does not solve problem completely. In the logs I have same line twice (not because of logback configuration because on Tomcat worked properly) and also double info about time, level, thread was printed in first record.
[2014-11-26 15:28:42,605] [INFO ] [MSC service thread 1-3 ] [stdout] [NONE ] [2014-11-26 15:28:42.605 INFO 8228 --- [vice thread 1-3] o.s.boot.SpringApplication : Starting application on LCJLT306 with PID 8228 (started by Piotr.Konczak in D:\servers\wildfly-8.2.0.Final\bin)
]
[2014-11-26 15:28:42,605] [INFO ] [MSC service thread 1-3 ] [o.s.boot.SpringApplication] [NONE ] [Starting application on LCJLT306 with PID 8228 (started by Piotr.Konczak in D:\servers\wildfly-8.2.0.Final\bin)]
As you can see in above example first record contains somehow additional timestamp, level and thread (I guess add by Wildfly during some redirect) while the second line is proper and expected.
My logback config has 2 parts - 1st inside app and 2nd outside app to make it possible to reconfigure in environments).
Inside the classpath:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<include file="/opt/appName/config/appNameLogConfig.xml" />
</configuration>
Outside the app (included one):
<?xml version="1.0" encoding="UTF-8"?>
<included>
<property name="DESTINATION_FOLDER" value="/opt/appName/logs" />
<property name="FILE_NAME" value="AppName" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${DESTINATION_FOLDER}/${FILE_NAME}.log</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--daily rollover-->
<fileNamePattern>${DESTINATION_FOLDER}/${FILE_NAME}.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%-5level %date %-30thread %-30logger{30} [%-10mdc{requestId:-NONE}] %msg%n</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="INFO"/>
<logger name="org.hibernate" level="INFO"/>
<logger name="com.wordnik" level="INFO"/>
<logger name="com.mangofactory" level="INFO"/>
<logger name="com.company.appName" level="INFO"/>
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</included>
Does anyone see possible reason or misconfiguration?
I know it is a little bit late but, if some of you face this problem, an alternative is: Don't disable the whole logging subsystem, instead just exclude slf4j libraries provided by JBoss/Wildfly, to use the one used by spring-boot.
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name='org.slf4j'/>
<module name='org.slf4j.impl'/>
</exclusions>
</deployment>
</jboss-deployment-structure>
Hope helps somebody.
I am using my own logging configuration, log4j2 xml instead of spring's logging and faced the same issue with the Wildfly. I commented the whole subsytem system for over-riding that.

Log file created; But no logs are getting stored

IDE: STS(Eclipse)
Query #1:
I have created a SpringsMVC Project using Template available in STS tool(New->Springs Project-> Springs MVC Project). I am trying to use log4j. My problem is a new log file gets created in the specified location. But it remains empty and logs are not getting stored.
File: web.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
File: log4j.properties
log4j.rootLogger = DEBUG, FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=D:/log.out
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
Query #2:
Also in the provided template there is already log4j.xml file in src/main/resources folder (a standard with resp to Maven web app). But modifying that file alone has no change in log file storage.
By Default when STS create template and log4j then root logger defined for console appender.
You need to change for appending the log in file.
Define file appender first in log4j.xml.
<appender name="file" class="org.apache.log4j.FileAppender">
<param name="File" value="E:\\util.log" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>
</layout>
</appender>
Then make change in root level.
<!-- Root Logger -->
<root>
<priority value="debug" />
<appender-ref ref="file" />
</root>
It will work.

Override logging in WildFly

I used tomcat and simply override default logging system. How to enable logging with logback on wildfly in my spring app?
My Logback.xml owrking on tomcat
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="WARN" />
<logger name="com.citronium.planstery" level="INFO" />
<logger name="org.apache.http.impl.conn.tsccm" level="ERROR" />
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
You can use logback to configure logging in your application. You can't use logback to configure logging for the server.
To use logback in your configuration you'll need to change the add-logging-api-dependencies to false or create a jboss-deployment-structure.xml that excludes the subsystem. You'll also need to include logback and slf4j in your deployment.
The first option of changing the add-logging-api-dependencies is a global setting for all deployments. The follow CLI command will change the value:
/subsystem=logging:write-attribute(name=add-logging-api-dependencies,value=false)
This option simply doesn't add any of the implicit logging dependencies to your deployment.
The second option of using a jboss-deployment-structure.xml will disable the logging subsystem for your deployment only. The following is an example file:
<jboss-deployment-structure>
<deployment>
<!-- exclude-subsystem prevents a subsystems deployment unit processors running on a deployment -->
<!-- which gives basically the same effect as removing the subsystem, but it only affects single deployment -->
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
Here is how we do this, by the way, we are using wildfly-8.1.0-Final.
First, make a jar file containing this class:
https://gist.github.com/xiaodong-xie/219491e0b433f8bd451e
Then put this jar file into "wildfly-8.1.0.Final/modules/system/layers/base/org/jboss/logmanager/main", and add a reference to this jar file in the module.xml file in the exact same folder.
Then put "logback-classic-1.1.2.jar" and "logback-core-1.1.2.jar" (You can use any version of logback you choose) into "wildfly-8.1.0.Final/modules/system/layers/base/org/jboss/logmanager/main", and reference those 2 jar files in the module.xml file.
Add the following to the "subsystem:logging" in the standalone.xml you are using:
<custom-handler name="logback" class="org.slf4j.bridge.SLF4JBridgeHandler" module="org.jboss.logmanager"></custom-handler>
And reference this handler in the root-logger element following:
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="logback"/>
</handlers>
</root-logger>
Here is an example of logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
<appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${JBOSS_HOME}/standalone/log/server-logback.log</file>
<append>true</append>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="LOGFILE"/>
</appender>
<root level="INFO">
<appender-ref ref="ASYNC"/>
</root>
</configuration>
And put this logback.xml file into "wildfly-8.1.0.Final/standalone/configuration" folder.
Add the following to the "standalone.sh" or equivalent in the "wildfly-8.1.0.Final/bin" folder.
-Dlogback.configurationFile=file:$JBOSS_CONFIG_DIR/logback.xml
Just under "-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties" line. There are 2 places in "standalone.sh" file.
=================================================================================
Or you can do it in a simpler way. :)
Put the 2 logback jar files to the "jboss.logmanager" module, and add "-Dorg.jboss.logging.provider=slf4j" to the "standalone.sh" file, the same position.
I found there are some logging missing if going this by the way, since Wildfly itself still using its own logging facility if going this way.
Have fun. :-)

Logging options for Slick

I'm createing a Play 2.1 app, in which I have decided to use Slick for database interaction.
However I can't find documentation about how to configure/enable logging for Slick.
Anyone knows this?
Slick doesn't do much of any logging above DEBUG level. In application.conf if you add the line:
logger.scala.slick=DEBUG
you're going to get deluged with information from the query compiler.
You're probably just interested in the session information (Connection pool management, query strings, etc). In which case, just add
logger.scala.slick.session=DEBUG
to your Play application's application.conf
For PlayFramework 2.5.0 without Slick
Add to all your database configurations
db.default.logSql=true
Add to your logback.xml file:
<logger name="logger.org.jdbcdslog.StatementLogger" level="INFO" />
All the statements will be logged.
Reference:
https://www.playframework.com/documentation/2.5.x/ScalaDatabase#How-to-configure-SQL-log-statement
For play with Slick 3.0, just use
<logger name="slick.jdbc.JdbcBackend.statement" level="DEBUG" />
To print only select statements, in play-2.2.1 with slick 2.0.0, in application.conf have:
logger.scala.slick.jdbc.JdbcBackend.statement=DEBUG
I'm not using Play at the moment, but configure it as you would use logback. This is a nice description for setting up Play logging.
One option is to add
logger.scala.slick=INFO
to application.conf, as per Play manual. The other, if you have a custom logback.xml, is to add there the following line:
<logger name="scala.slick" level="INFO" />
Slick seems to use slf4j for its logging. So you might want to add a dependency on something like slf4j-simple to your project and set the desired log level for the Slick classes.
I've tried to integrate the logback.xml with the Slick logger but it doesn't work.
Modifing logger.xml (get it the latest version from GitHub based on your version) and adding the slick logger, instead, works.
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$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 %n%message%n%xException%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
</encoder>
</appender>
<logger name="play" level="INFO" />
<logger name="application" level="DEBUG" />
<!-- Off these ones as they are annoying, and anyway we manage configuration ourself -->
<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
<logger name="scala.slick" level="SQL" />
<root level="ERROR">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
For slick 3.1.0, paste this in logback.xml in your resources directory:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="application" level="DEBUG"/>
<logger name="com.zaxxer.hikari" level="INFO"/>
<logger name="slick" level="INFO"/>
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
In my case I had to add <logger name="slick" level="INFO"/> to my log4j2.xml file. I'm using Slick 3.0.3 with Spray 1.3.3 and Log4j 2.1