custom-logger | simple , customizable logger for node
kandi X-RAY | custom-logger Summary
kandi X-RAY | custom-logger Summary
simple, customizable logger for node
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of custom-logger
custom-logger Key Features
custom-logger Examples and Code Snippets
Community Discussions
Trending Discussions on custom-logger
QUESTION
We are trying something new and posting the question here to see if it is possible.
TL;DR Overriding a parent custom ConfigurationFactory in a web app.
Scenario: We have bunch of web applications. Some of those web applications write the logs to same log file and other web applications to application related individual log files. So I have written a CustomLoggerConfigFactory (let's call this as parent configuration for the sake of discussion) and bundled that up in a custom-logger-util.jar and using this jar as a dependency in the web applications and the logger is getting initialized during web app startup. This configuration has a RollingFileAppender after initialized writes the logs to a file named: common-logs.log which is working fine. Here below is the code for CustomLoggerConfigFactory.
Problem: Now my question is, say in a web application B, also where the common-logger-util.jar is used as a dependency - how can I extend the CustomLoggerConfigFactory to override the RollingFileAppender to write the logs to appB.log file instead of common-logs.log programmatically and without using config files and keeping the rest of the configuration the same i.e. to use the Console appender, Loggers(including RootLogger) as defined by parent config factory? Can anyone please explain how to achieve this?
Thanks in advance.
...ANSWER
Answered 2020-Dec-09 at 16:17I have designed my custom config factory and see that as one way to accomplish this.
The solution is built on Java 8. The interfaces in Java 8 now allow you to define default implementation for the methods and used them. The log4j2 provided ConfigurationFactory
is already an abstract class but I wanted to separate the creation of configuration and to the individual components having the default implementation.
The LoggerConfigFactory
in the below image is the custom default implementation that can be used in any of the other apps just by including it (however, in my case, I packaged CustomConfigBuilder, LoggerConfigFactory and LoggerConstants in a jar file).
In the event in the application if any or all of the individual components needs to be defined, all it is required is to create config factory class (AppSpecificLoggerConfigFactory) that extends the default LoggerConfigFactory.
This worked!! Here below is the code for the sake of reference.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install custom-logger
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page