-
Notifications
You must be signed in to change notification settings - Fork 40.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overriding logging properties like FILE_LOG_PATTERN #1788
Comments
This would be very useful as I also have just come across the need to override the pattern for our logging indexer +1 |
+1 - This would indeed be very useful. We have the same need - and would also like to set other properties for use in logback config in the same manner. |
+1 |
Seems like a popular request. I'll assign to 1.2 and take a look but we are really near GA so it might need to be pushed back to 1.3. |
Since I raised this feature request I needed to log to 2 separate files. 1 standard log file (with a customized format containing MDC info) but also 1 log file to be used for Logstash/Elasticsearch with custom layout class. |
@marceloverdijk Sounds like a fairly complex scenario so it probably won't be possible with the properties. Have you tried defining your own |
Yes I'm using a custom logback.xml now. Btw I think it should be possible to define multiple appenders via properties. With standard log4j properties file this is also possible. Thinking of it I wonder if it would be possible to define log4j.* properties (in applucation properties) and use them to initiate log4j? Just thinking loud to see options for customizations and per env config. |
Have not tried it myself - but for environment specific logback configurations I think it is possible to do that using logback includes. Create a 'master' logback configuration file that includes another environment specific logback-staging.xml - that has root tag 'included'. logback-master.xml:
logback-test.xml:
When launching your application set the LOGBACK_ENV system property, e.g. System.setProperty("LOGBACK_ENV", "test") (this will of course not be necessary when the current issue has been fixed - at that time we can simple set a property in application.properties instead) and if the file exists you should see a log line from logback:
|
I'm afraid I need to push this back for now :( |
Hopefully another day maybe :-)
|
+1 |
+1 |
+1 |
+1 thanks very much. |
+1 Thanks! |
+1 |
+1 |
1 similar comment
+1 |
I also struggle with same issue because the log message issued twice. |
👍 the same here, i want to use the The problem is, that i need to get the |
+1 need this feature, |
+1 |
Missing it a lot... When will it be done? |
+1 |
+1 for spring-cloud-sleuth-correlation including a correlation id in the logs. |
Makes spring properties starting with prefix "logging.properties." available as system properties (without the prefix) before the logging system is initialized so they can be used in logging configurations that support them (e.g. logback). Closes spring-projectsgh-1788
For anyone watching this issue there is now a new I'd appreciate any feedback on this approach, does it work for people? |
How does this differ from using Spring Cloud Config? A couple of months ago I needed the functionality for determining which profile was loaded and was able to accomplish with Spring Cloud Config. Essentially loading profile specific logback configurations. Is this the same concept? |
@ccit-spence can you point me at a sample to show me what you mean? |
@philwebb I didn't have to really add anything except for configuring the service to use Spring Cloud Config It was really the only thing I have to do. In each service I have the following logback profile specific files. I do not have a logback.xml file. Only with its respective profile as below.
Your example seems to add more robust capabilities. I am pretty sure the reason why Spring Cloud Config worked is that it refreshes the logback config after the initial load allowing for later processing during boot. |
@spencergibb @dsyer How does Spring Cloud Config support these profile specific logback configs? Is this something we should bring into Spring Boot? How does it deal with multiple active profiles? |
IIRC there is some hackery in Spring Cloud Commons to explicitly give log configuration a chance to refresh before starting to main application context. Remember that Spring Cloud always has a parent "bootstrap" context and it is there that you can set up things that need extra logic before the main context has started. I'm not sure there is anything magic about it in general, but logging systems require special treatment to get them initialized early, so I think that led to a special case. |
@philwebb I like the approach as it seems very flexible. Based on this is it possible to update properties that are defined in defaults.xml like the CONSOLE_LOG_PATTERN and FILE_LOG_PATTERN from another property source? It seems like it would be useful to override just these and not completely define a new configuration just to override this. |
@rob-baily I've raised #3367 to consider this. We can't use the same |
I am trying to use springProfile tag in logback.xml to have profile specific logging but spring boot is ignoring this and all tags after this.(I am using spring boot version 1.2.4 Release) -ERROR in ch.qos.logback.core.joran.spi.Interpreter@6:88 - no applicable action for [appender], current ElementPath is [[configuration][springProfile][appender]]I tried putting the same configuration in logback-spring.xml but spring boot not recognizing and loading this file itself. |
@rakesh9 The new feature is coming is version 1.3.0. You can't use it until this unless you want to go against a SNAPSHOT build. |
@rakesh9 as @rob-baily said this is a new feature not and won't be available in 1.2.x. You'll also need to use |
@rob-baily @ philwebb Thanks for the update..I missed observing the version...I am new to spring-boot.. |
@philwebb Love the the new The |
@edward-smith It only accepts a single name at the moment, but it should be easy to fix that. I'll open a new issue. |
+1 |
@thefalconfeat it's already implemented (and this issue is closed FWIW). |
Is there any support for this functionality in |
@wilkinsona Great, thanks. I think I'll be able to express my setup in XML, so this feature is still a big help. |
Any chance to see this feature (springproperty) extended for log4j2 ? |
@Tetradeus We're not sure that it's possible with Log4j2. If it is, the change would be made as part of #4032. |
I want to know where Spring specify that spring boot 1.2 not support log pattern set by application.properties, man, I take a while to get it. |
The string |
Feature request for adding support for overriding logging properties via application.properties/yaml.
E.g. I want to easily override the FILE_LOG_PATTERN property.
To define this in the application.properties/yaml also gives the benefit that I can change it per environment.
Boot already offers
Something like below maybe?
Reference: http://stackoverflow.com/questions/26629197/overriding-the-file-log-pattern-if-possible-per-env
The text was updated successfully, but these errors were encountered: