I have deployed a WAR to AWS Elastic Beanstalk on environment with Tomcat 8.5 with Java 8. The app loads and is working fine. However, when I go to check the logs (Environment -> Logs -> Last 100 lines OR Full Logs) I do not see the logs written by the app. There are some other logs like tomcat/activity/boot etc, but not the logs written by my application. The logs work as expected when running locally, just not on AWS.
Below is my logback.xml file:
<configuration debug="true">
<appender name="APPLOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/my_app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>/var/log/my_app_%d{yyyy-MM-dd}_%i.log</FileNamePattern>
<maxHistory>7</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>5MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %-5level %c{1} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="LOGFILE" />
</root>
</configuration>
In one of the Medium post I learned that we need to configure the EB environment so that the application's logs are included in the logs bundle. So I put the following config file in the application's resources directory:
files:
"/opt/elasticbeanstalk/tasks/bundlelogs.d/applogs.conf" :
mode: "000755"
owner: root
group: root
content: |
/var/log/*.log
"/opt/elasticbeanstalk/tasks/taillogs.d/applogs.conf" :
mode: "000755"
owner: root
group: root
content: |
/var/log/*.log
But that did not help, there was no change in the app's log behavior.
This has been a frustrating ordeal so far, hoping for some help.
I had faced similar issues with logging when I deployed my app to AWS.
A couple of things of note:
(1) The config file is correct (that's what I used), but that needs to go into an .ebextensions folder in your webapp directory:
(2) You will need to change the location of your log file. Your app can't write to the var/log folder, but can write to the var/log/tomcat folder because of folder permissions issue.
You can find more details on my question here: AWS Elastic Beanstalk Application Logging with Logback
Hope it works out for you!
Related
I recently started working in a Spring boot application. The application uses spring-logback for logging implementation.
The application is bundled as a war in different environments. However, the location of writing logs is different in each environment and is mentioned in a logging.properties file.
Therefore, I currently have to change the location before preparing the war every time.
How can I set the path of the logs in the Tomcat configuration so that the path is auto-picked for an environment.
Currently mu logback appender looks like this:
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logging.file}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${logging.file}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>${log.file.size}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>${log.file.history}</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${logging.pattern.file}</pattern>
</encoder>
</appender>
All the properties here are picked from logging.properties file inside the src/main/resources
spring-boot provides several logging.* settings that can be applied in application.properties, like:
logging.level.=DEBUG
logging.file=myfile.log
logging.path=d:/logs/
If you set logging.path, Spring Boot writes spring.log to the specified directory. Names can be an exact location or relative to the current directory.
I have a Java-standalone REST application, which is inside Tomсat. I need to output logs to a file, I use logback. But logs are not written to the file. They are displayed in the console, although I removed the console appender. If you try on a Windows machine, everything goes fine. Trying on RedHat (does not have a GUI), the logs are not output to the file (although they should) and are output to the console (although they should not be displayed). The application works exactly, responds to queries.
Logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="DEV_HOME" value="/var/tmp" />
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${DEV_HOME}/mytest.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${DEV_HOME}/mytest-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>2KB</maxFileSize>
<maxHistory>4</maxHistory>
<totalSizeCap>10KB</totalSizeCap>
</rollingPolicy>
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="file" />
</root>
</configuration>
In Eclipse I do export to Runnable jar file, I throw it on a Linux machine. I run as follows:
java -jar test.jar &
Yes I had the same scenario with jboss EAP 7.0 every thing was working fine on the window machine but as soon as i was taking it to linux machine . it wont write a single word.
[application.properties for logging]
second i had move log4j.properties in Jboss bin folder. application.properties file and the same file in springboot application resources.
After that restart the server and you will found the loggs written on the specified folder
I'm using play framework in a project. In order to config the log file related information, I use logback to config it. Here is the sample configuration:
<appender name="DEBUGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/usr/frank/logs/debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover with compression -->
<fileNamePattern>debug-log-%d{yyyy-MM-dd}.gz</fileNamePattern>
<!-- keep 1 week worth of history -->
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date - [%level] - from %logger in %thread %message%n</pattern>
</encoder>
</appender>
When I run the test like ./activator test or run the application in dev mode ./activator run, I can find the log file get created at the place specified at the file section. But when I run the application in production mode, like ./activator start, the file will not get generated.
Can anyone tell me why?
In Production mode you have to pass the parameter logger.file as shown below.
-Dlogger.file="/usr/frank/logs/debug.log"
My java EAR application runs on 2 application servers. Each write the logs locally with log file names. I want to know how to add the unique app server name to the log file name that is being written in each server. This would help me identify the files from each server when I am looking into the log files after downloading them from server and while sending to coworkers for debugging. Currently we have to put them into separate folders as both folders have files with the same names. Thank you.
Following is the snippet from logback.xml that names the file
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logfile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>logfile-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 10MB -->
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
If you use groovy configuration for logback, you can try
import java.net.InetAddress
println InetAddress.getLocalHost()
This will give you the local server name and IP address.
I saw several questions on the topic, but since they are rather related to errors I don't think this is a duplicate.
My problem is that I can't get any logging out of a .war I'm deploying on JBoss 6 EAP, there are no errors logged also however. There is also a file named as my .war created under the /log folder in JBoss, but it is also empty.
The .war deploys fine and works. Since I'm using Spring I can't even see it initializing it's contexts.
Logging works perfectly under Tomcat 7 with the same .war.
I have created a log4j.xml and placed it in my WEB-INF/classes dir (I also tried in /WEB-INF):
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
</layout>
</appender>
<root>
<priority value ="info" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
I'm using log4j 1.2.17, Spring 3.1 and JBoss 6 EAP.
Any help greatly appreciated,
Thanks
Unlike JBoss AS 7.1.1, JBoss EAP 6 activates per-deployment logging configuration if it finds a logging config file: https://community.jboss.org/message/776182#776182
I suggest removing log4j.xml. If that doesn't help, modify your jboss configuration to set the system property org.jboss.as.logging.per-deployment to false. In my case, I had to add this line to standalone.conf:
JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false"
In my case, EAP 6.0 in domain mode, I had to set org.jboss.as.logging.per-deployment = false as an environment property for the specific server. Setting it as a "System Property" as stated in the EAP 6.3 docs did not work.