spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.83k stars 40.61k forks source link

LOG_FILE_IS_UNDEFINED log file is being created in boot 1.4.5 #8675

Closed ezraroi closed 7 years ago

ezraroi commented 7 years ago

when using vanila Spring boot 1.4.5 with the following logback configuration:

<configuration>
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>${LOG_FILE}</file>
    <encoder>
      <pattern>%logger{35} - %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="FILE" />
  </appender>

  <root level="INFO">
    <appender-ref ref="ASYNC" />
  </root>
</configuration>

and the following application.properties:

logging.file=/tmp/myapp.log

Empty file is being created in the name of LOG_FILE_IS_UNDEFINED. Looks like 2 async appenders are being created, one with LOG_FILE_IS_UNDEFINED as the file name and another one with the file name from the properties. The LOG_FILE_IS_UNDEFINED is stopped immediately and this is why the file is empty.

@regevbr

philwebb commented 7 years ago

Have you tried using a logback-spring.xml file rather than logback.xml? I have a feeling that logback might be initializing itself before we can set the LOG_FILE property.

If that doesn't work, could you please share a small sample application that shows the problem?

regevbr commented 7 years ago

We are using the logback-spring.xml file already and the issue still persists

philwebb commented 7 years ago

@regevbr You have the same issue?

If that doesn't work, could you please share a small sample application that shows the problem?

Are you able to provide a sample?

regevbr commented 7 years ago

Hi, Roi and I are working in the same team. We will provide a sample application as soon as we can.

ezraroi commented 7 years ago

Hi, after changing the file to logback-spring.xml it is working fine! thanks

pksinghus commented 7 years ago

I am having this problem with spring boot 1.5.2.RELEASE while using logback-spring.xml

application.properties -

logging.config=classpath:logback-spring.xml
logging.file=app.log

logback-spring.xml -

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOG_FILE}</file>
    <encoder class="extension of PatternLayoutEncoder">
        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5}  - %msg%n</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>${LOG_FILE}.%i</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>9</maxIndex>
    </rollingPolicy>
    <triggeringPolicy
            class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>10MB</maxFileSize>
    </triggeringPolicy>
</appender>
philwebb commented 7 years ago

@pksinghus Try dropping the logging.config property, it shouldn't be needed if you're using logback-spring.xml. If that doesn't work please open a new issue and share a project that replicates the problem.

stguitar commented 5 years ago

I really really hate to comment on a closed ticket, but I am not finding much info about this issue these days on the web that feels applicable to my application.

We're using spring boot 2.1.4, and I have the same setup as the previous post, but do not have the logging.config property set. We have a logback-spring.xml file in the project.

When I run this application, I get these files named LOG_FILE_IS_UNDEFINED that are being created. They are dated, as if they are rolling over after some period of time.

Going off the commentary above, I am not sure what else I should try to avoid this behavior.

pksinghus commented 5 years ago

This happening because you have some spring cloud artifact in your pom. Remove it and this error will be gone. Don't include cloud unless you are integrating with cloud which you shouldn't because your Java app doesn't need to know where it is running.

stguitar commented 5 years ago

Thanks for the quick reply!

Yes, that is indeed true. I am trying to use Zuul in this application. I am using Gradle btw, but my entries in the dependencies block has implementation 'org.springframework.cloud:spring-cloud-starter-netflix-zuul'.

I had also read on some other tickets that I should use the spring cloud BOM to manage this dependency, so I have the following in my build.gradle file as well:

ext {
    set('springCloudVersion', "Greenwich.SR1")
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

Are you suggesting that I remove all of this?

pksinghus commented 5 years ago

Removing all cloud business resolved this issue for me. I wasn't using any of it. Some of it was getting transitively pulled.

stguitar commented 5 years ago

cool, gotcha. Yea, sadly, I don't think that'd work for my application since I need to use Zuul, but thanks for the info! I am hoping I can find something else causing this...

amounib commented 4 years ago

So, for us, we need the spring cloud components. Found that adding <include resource="org/springframework/boot/logging/logback/base.xml" /> right after the configuration tag at the top resolves the erroneous file generation

So our file starts

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml" />
    <appender name="JSON" class="ch.qos.logback.core.rolling.RollingFileAppender">
DachengChen commented 4 years ago

this is my logback-spring.xml file and works, property should direcly after configuration

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="LOG_FILE" value="/var/log/application.log"/>
    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
    <include resource="org/springframework/boot/logging/logback/file-appender.xml" />
    <root level="INFO">
        <appender-ref ref="FILE" />
    </root>
</configuration> 
shithanshu-beltech commented 2 years ago

In My case, it was a stupid mistake I commented logging.pattern.file, logging.file.name and when logback was parsed (logback didn't contain these details) after application .properties it wasn't able to find any pattern hence was throwing the error LOG_FILE_IS_UNDEFINEDLOG

Make sure you check your application properties and logback.xml (either of them should contain the configuration)

youngledo commented 2 years ago

When I used bootstrap.yml, the problem still existed.

image
shithanshu-beltech commented 2 years ago

@youngledo Can you Share your logback-spring.xml file

youngledo commented 2 years ago

@shithanshu-beltech Uploaded a sample code, you can directly run it to see

sample.zip

In addition, I found that adding this dependency can solve the problem of the sample project, but it still cannot solve my project problem.

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
        </dependency>
shithanshu-beltech commented 2 years ago

@youngledo The logback is unable to understand if it needs to read those properties from bootstrap.yaml So while running the app you need to mark bootstrap.yml as config location

-Dspring.config.location=src/main/resources/bootstrap.yml Add this to your run argument and it will start working Let me know if you want to keep bootsrap.yml as different from application.properties