Logback can't access the specified logfiles - logback

I'm running my app on Websphere Liberty with logback logging. I defined an appender in logback.xml but on startup logback throws FileNotFoundException.
This is the error output:
09:37:33,065 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[RollApp] - Failed to create parent directories for [F:\server\wlp-ev-21.0.0.11\usr\servers\defaultServer\"F:\server\wlp-ev-21.0.0.11\usr\servers\defaultServer\logs\log-output.log]
09:37:33,066 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[RollApp] - openFile("F:/server/wlp-ev-21.0.0.11/usr/servers/defaultServer/logs/log-output.log,true) call failed. java.io.FileNotFoundException: "F:\server\wlp-ev-21.0.0.11\usr\servers\defaultServer\logs\log-output.log (Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch)
at java.io.FileNotFoundException: "F:\server\wlp-ev-21.0.0.11\usr\servers\defaultServer\logs\log-output.log (Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch)
Here's my appender block in logback.xml
<appender name="RollApp"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>"${server.output.dir}/logs/log-output.log</File
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %c{2} - %m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>"${server.output.dir}/logs/log-output.%d{yyyy-MM-dd}.log.gz</fileNamePattern
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
Did anyone ever encounter this problem?
I'm 100% sure the files exists because I can copy and paste the path from the error output into an explorer window and the file/folder opens!

Looks like the leading " is unexpected in the fileNamePattern.

Related

Java web app catalina logs not written to log file when running in Eclipse

I have a Java web app that I run in Eclipse for my development environment. I use logback for logging to a custom file. The problem is certain logging statements, specifically those that traditionally go to catalina.out, do not end up in my log file. They do show up in my Eclipse console, but not in my custom logback log file.
When I run the same app in tomcat outside of Eclipse (via startup.bat), those catalina logging statements do get captured in a catalina.out file. But when running in Eclipse no catalina.out is created, so those logs don't persist.
Here's my logback-test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- RollingFileAppender that rolls based on size and time -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/mylog.log</file>
<encoder>
<pattern>%date [%thread] %-5level %logger{10} [%file:%line] - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${catalina.base}/logs/mylog.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file at most 20MB; keep 10 files worth of history, max total 20GB -->
<maxFileSize>20MB</maxFileSize>
<maxHistory>10</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>logback-test %date [%thread] %highlight(%-5level) %logger{10} - %msg%n</pattern>
</encoder>
</appender>
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>logback-test %date [%thread] %highlight(%-5level) %logger{10} - %msg%n</pattern>
</encoder>
</appender>
<!-- set logging levels for specific packages -->
<logger name="org.apache.catalina.startup" level="INFO"/>
<!-- set level of the root logger and associate it with both appenders -->
<root level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
<appender-ref ref="STDERR"/>
</root>
</configuration>
This answer resolved my question: https://stackoverflow.com/a/5045247/3368818
Apparently, if, while running an app on tomcat via Eclipse, you want to capture the catalina logs in a file, you need to specify that via the Eclipse tomcat launch configuration settings.
I guess in a way this makes sense in that the catalina logs are perhaps not application specific, so maybe outside the scope of logback appenders. But on the other hand, shouldn't they get written to a log file by default anyway, just as they do if you launch your tomcat server outside of Eclipse?

slf4j, logback, the target compressed file named exist already

logback 1.1.5 + slf4j 1.7.4.
Rollover at midnight
00:00:00,163 |-INFO in c.q.l.co.rolling.helper.RenameUtil - Renaming file [/opt/wls/appl/log/out.log] to [/opt/wls/appl/log/out.log1294410077875834.tmp]
00:00:00,164 |-INFO in ch.qos.logback.core.rolling.helper.Compressor - ZIP compressing [/opt/wls/appl/log/out.log1294410077875834.tmp] as [/opt/wls/appl/log/archive/out/out-2018-09-04.10.zip]
But after some seconds rollover starts again
00:01:52,551 |-INFO in c.q.l.co.rolling.helper.RenameUtil - Renaming file [/opt/wls/appl/log/out.log] to [/opt/wls/appl/log/out.log1294522459498363.tmp]
00:01:52,551 |-WARN in ch.qos.logback.core.rolling.helper.Compressor - The target compressed file named [/opt/wls/appl/log/archive/out/out-2018-09-04.0.zip] exist already.
There are 2 applications on 2 virtual servers of WLS. Both of applications use separate home folder with your own logback.xml.
logback.xml is
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${PRG_HOME}/logs/out/out-%d{yyyy-MM-dd}.%i.zip</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n%ex</pattern>
</encoder>
</appender>
<appender name="ASYNC_COMMON" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>32000</queueSize>
<appender-ref ref="ROLLING" />
</appender>
What can I do?
You can try to add <prudent>true</prudent> to your RollingFileAppender. This should allow for multiple JVMs writing safely to the same file.
There are some restrictions that apply to prudent mode, though. Log-file compression is not allowed, for example.

Logback configuration with external file, log file is empty

I try configure logging via external file. WLS 10.3.6, startWebLogic.properties include:
-Dproject_name_home=D:\path\to\project_home ^
-Dlogging.config=${project_name_home}/conf/logback.xml ^
-Dlogging.path=${project_name_home}/log ^
-Dlogging.file=${project_name_home}/log/out.log ^
-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Slf4jLogger
out.log was created in project home folder, but it is empty.
according to log logback.xml used inside application, not from external file:
19:05:27,621 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
19:05:27,622 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
19:05:27,622 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [zip:D:/Weblogic10.3.6/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/project_name/pjckx7/war/WEB-INF/lib/_wl_cls_gen.jar!/logback.xml]
What's wrong? Please help to configure logging with external file.
My external logback.xml is:
<configuration>
<property name="LOG_PATH" value="${project_home}/log" />
<property name="LOG_FILE" value="${LOG_PATH}/out.log" />
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/archive/out/out-%d{yyyy-MM-dd}.%i.zip</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n%ex</pattern>
</encoder>
</appender>
<logger name="package.name" level="debug">
<appender-ref ref="ROLLING" />
</logger>
</configuration>
Logging configure inside application, application.yml is:
logging:
level:
package:
name: DEBUG
path: ${project_home}/logs
pattern:
console: "${CONSOLE_LOG_PATTERN:%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %maskedM%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}}"
file: "${FILE_LOG_PATTERN:%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:%5p} ${PID:- } --- [%t] %-40.40logger{39} : %maskedM%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}}"
So, the next steps for logging configuration via external logback.xml are:
set logging.config (path to external logback.xml) in WLS start file.
also logging levels defined in application.yml need configure in WLS start file (logging.level. parameter, according to question need set logging.level.package.name parameter).
levels for another packages (not defined in application.yml) are configure in logback.xml.
other parameters (logging.path, logging.file) should be deleted.
all other parameters are configure at external logback.xml as before.

Unable to log Uncaught exceptions with Logback

I wrote a web-app with various frameworks(jsf,Spring,Hibernate) and my logger library is Logback and slf4j.
At the moment I'm not able to display uncaught exceptions(for example NullPointers) in log file.
This is my logBack.xml
<configuration debug="true">
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${CATALINA_HOME}/logs/jsfDemo.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>jsfDemo.%d{yyyy-MM-dd}.log.zip</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="FILE" />
</root>
</configuration>
when I execute this few lines of code with uc=null
public void nullPointerMethod(UserCredential uc){
LOG.debug(">>login(uc)");
if(uc == null){
throw new NullPointerException();
}else{
//do something
}
LOG.debug("<<login(uc)");
}
in the logFile I see only
>>login(uc)
but I want to see stackTrace of NullPointer. What's wrong?
You can use SLF4JBridgeHandler:
Essentially, the idea is to install on the root logger an instance of SLF4JBridgeHandler as the sole JUL handler in the system. Subsequently, the SLF4JBridgeHandler instance will redirect all JUL log records are redirected to the SLF4J API based
Basically you only need call SLF4JBridgeHandler.install(); in your main method and configure logback this way:
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>

Excessive "-INFO...RenameUtil - Renaming file..." in Jetty8 stderrrout with Logback RequestLogImpl

My app runs in Jetty8 and is leveraging Logback's RequestLogImpl (which is just great, by the way). Recently we discovered that if logback has a problem rolling over files, the logging message that would have alerted us to that appears nowhere because we had not configured Jetty to redirect its stderrout to any log file. My current release corrected that problem, but now I notice an excessive volume of INFO messages from logback in the jetty stderrout file like
06:32:14,893 |-INFO in c.q.l.co.rolling.helper.RenameUtil - Renaming file [/data/logs/md-stage-app4.dev.mgg.request.3.log] to [/data/logs/md-stage-app4.dev.mgg.request.4.log]
I only really care about these messages if the rename failed or something, which these messages come out as WARN. How can I get the logback stuff to just log at WARN and above into the jetty stderrout logfile?
My app itself does, indeed, <root level="info"> the root logger.
etc/jetty.xml has the following excerpt:
<!-- Logback Access Log implementation -->
<Ref id="RequestLog">
<Set name="requestLog">
<New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl">
<Set name="fileName">etc/logbackAccess.xml</Set>
</New>
</Set>
</Ref>
etc/logbackAccess.xml is:
<configuration>
<!-- always a good activate OnConsoleStatusListener -->
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<appender name="SIZE_ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>/data/logs/md-app3.request.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>/data/logs/md-app3.request.%i.log</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>5</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>1MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%h %l %u [%t] "%r" %s %b%n%fullRequest%n</pattern>
</encoder>
</appender>
<appender-ref ref="SIZE_ROLLING" />
</configuration>
The status messages are printed because of the line
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
in logback-access.xml (etc/logbackAccess.xml in your case). By adapting OnConsoleStatusListener and OnPrintStreamStatusListenerBase, you should be able able to create a custom StatusListener which prints status messages except INFO messages originating at RenameUtil.