I was wondering if there is any way already implemented in Apache Camel to be able to log to different loggers depending on the route. I am using Spring DSL to create the routes. My use case is that I want a different log file for each route I am defining.
Is that possible?
You can enabled MDC logging, which then include details about which route is currently being logged from: http://camel.apache.org/mdc-logging.html
Then the logging framework you use, such as log4j, logback, etc. can be configured to log to different appenders based on a MDC key (eg camel.routeId)
Related
I am running a spring boot application. for logging purpose we have used spring logback.
there is spring-logback.xml file where we define log level more likely at package level.
is there a way to group logger (may be at feature level) and package names are not same as feature name , which can have common configuration. more like instead of changing each class log level of feature . changing log level at feature which changes log level of all linked/grouped loggers.
Spring support grouping in configuration properties rather than in logback-spring.xml
for more info
https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/html/boot-features-logging.html#boot-features-custom-log-groups
My program has an underlaying system that persist every log in elasticsearch.
I have a class that fetches data online and logs it with slf4j log.error(data).
This allow the underlaying system to persist the log in elasticsearch, but it also floods the console with every fetched data.
I wish to disable the consoleAppender just for this specific class.
I've seen other post where people would disable the consoleAppender with logback or would exclude all logging from a specific class, but I couldn't find any information on how to disable one logger in one class.
Is this possible?
It sounds like you just need to set the logging level for that class. Set it to ERROR, WARN or another level, depending on the level of the messages that are flooding the console. Try modifying the application.properties file by adding something like:
logging.level.com.test.MyClass=WARN
I am building an application (Spring Boot 1.4.2) where i would like to offer an administrator the option to enable syslog but i want to avoid him/her having to manually edit any config files - in this case logstash-spring.xml.
Therefore i am trying to understand how i can achieve using a logback-spring.xml file as a baseline (e.g. define file based log options, levels etc. - settings i dont want the administrator to change) and on top of that provide a functionality at runtime where an administrator can add or change a syslog appender.
I have listed what i see as requirements:
The changes made to the Logger should be persisted after the Spring Boot application is restarted.
Ideally the syslog server info (name, port) are kept in my persistence layer (H2, hibernate) but i am not sure if that is possible as i guess the logging framework is being injected prior to my persistence layer?
The syslog appender that i want to add should be referenced by root logger so that all the packages i have configured logging for would go to syslog (not sure if this is just "how it works per default")
Also i dont know if i could simply treat logback-spring.xml as a regular XML object and use for example JAXB to manipulate that file and use the autoscan feature of Logback to simply read in the new changes?
I have played around with defining a Logger #Bean:
#Bean
public Logger logger() {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
// excluded implementation
}
This is being picked up by Spring Boot but that brings me to the 2 items i have listed above that i dont know how or where i would store the syslog server information the administrator would provide.
UPDATE:
I wrote the following which meets the 3 requirements above however i would appreciate any feedback on the actual implementation as i am very new to Spring and Java.
GitHub repository with implementation - spring-boot-logback-syslog
I managed to use the example i posted in my Github repo in my designated application and with that i am answering my own questions based on the implementation in that repo.
Please refer to the README for full details on how it was implemented.
UPDATE: As part of Spring Boot 1.5.1 there is an actuator that can set the logging level during runtime: Production Ready Loggers
Not necessarily 100% related to this topic but this was one of the requirements i had for the implementation as well as changing syslog related settings.
I have a large, Spring-based eCommerce framework as a codebase which makes use of pre configured log4j. I can override property values defined in log4j.properties.
I'd like to configure log4j to log asynchronously to console/file, I've attempted to define new/override appenders but am not seeing any output to console and am unsure why.
Is it possible to wrap current log4j into asynchronous calls?
I have a Spring boot application which use logback.xml for logging configurations.I am looking for options to dynamically change log level.
For instance if I have deployed an app with loglevel as ERROR,Let say I want to change this to INFO but I don't want to redeploy/restart my JVM.
Is there any possibility we can configure logback.xml like config server to achieve this
You can configure Logback to Automatically reloading configuration file upon modification
Yes, this is quite possible. Expose a rest endpoint where you supply the className and log level. With slf4j you can get the LoggerContext and change the level.
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.getLogger(className).setLevel(Level.valueOf(level));
Apache Commons logging and others have similar features.
If you are using spring cloud then you can have this in your yml file
logging:
level:
root: INFO
Then you can change it and refresh the configuration using actuator refresh to fetch new configuration changes no need to restart the service.
Also if you need some sort of UI to do this stuff you can explore the Spring-cloud-dashboard It is pretty cool and uses the features from the actuator to do and show you a lot of stuff not only changing log levels.