How to set Apache Pulsar as the appender to Log4j2? - log4j2

I've been tasked to setup a logging system that uses Apache Pulsar as the appender to Log4j2. I'm really lost on how to set this up and there doesn't seem to be any documentation/examples to go by. Does anyone have an idea how to go about this?

I found an example in the Pular Appender's test project. I would suggest you look at that as it shows 5 different configurations. However, I would not recommend the SerializedLayout as it can lead to security vulnerabilities.

Related

Logger service using logging package in Angular Dart

There is a mention in the docs of using the logging package to create a proper logger service. Given the features in the logging package it would be nice to be able to get the angular component tree as the logger full name.
I tried to play a bit with the dependency injection system to get the injector tree, so that I could reconstruct the app structure for the loggers. But this proved to be too tricky.
Is there a way to do this, or alternatively, is there a canonical logger service that I could use? It seems to be a pretty basic feature so it must be available somewhere.
I'd look at the logging package for help here.
This is not Angular-specific, but it supports tested loggers.

Log4j is already not configured via logback.groovy file in Grails 3.2.8

As we know by default logging in Grails 3.0 is handled by the Logback logging framework and can be configured with the grails-app/conf/logback.groovy file. The good part of this was that the configuration inside this file was applicable for the Logback and Log4j implementations (tested successfully in Grails 3.1.2). After we migrated to use Grails 3.2.8 from Grails 3.1.2 (as I said before), it seems that the configuration inside the logback.groovy file is not used by the Log4j and it should be configured in other way - at runtime.
I made a deep research in this to ensure that this is really the way it is configured now and it seems that if I am using the default Log4j logging:
org.apache.log4j.Logger.getLogger("name").info("TEST");
is not working at all. To make the information populated into the output log file, I should use the default SLF4J API:
org.slf4j.LoggerFactory.getLogger("name").info("TEST");
The problem here is because that we have a lot of places in the code where the logging is implemented using Log4j approach and now - nothing is written in the log file.
So I have two questions here. The first one - is this the exact way how Grails implemented this behavior (as nothing is mentioned in the official documentation - Grails 3.2.8 Documentation). The second one - is the XML or RUNTIME configurations are the best way to configure the Log4j, so use it as before. If yes - the bad thing here is that we should maintain two same configurations at a time. Is there any other way to configure the Log4j to use the same configuration as the Grails Logger.
P.S. There is no need to publish any code, as all are just default configurations.
Thanks a lot!
appender('STDOUT', ConsoleAppender) {
encoder(PatternLayoutEncoder) {
charset = Charset.forName('UTF-8')
}
}
root(ERROR, ['STDOUT'])
logger("<package_name>", DEBUG)
List artifacts = ["conf", "controllers", "domain", "init"]
artifacts.each { artifact ->
logger("grails.app.${artifact}.<package_name>", DEBUG)
}
After writing this, you can add logger for debugging in any artifacts mentioned above like:
log.debug "Any Message"
For more setting you can read here: https://logback.qos.ch/manual/groovy.html

which is the best way for configure log4j2

I am developing one automation testing framework for a web application testing. For this automation framework I want implement logging with log4j2.
In web I found that there is 4 different way to configure the log4j2 configuration
1) .xml
2) .yml
3) .properties
4) .json
I am confuse which configuration will be better for which purpose. Can anyone explain me for what kind of application/situation which configuration is suitable.
Also I want to know how I can implement log4j2 from start to end (any link)
You're completely free to use any! It's a matter of personal preference.
You can see that they have the same capabilities in the configuration documentation.
A properties file is definitely the simplest, but there's probably more documentation using XML. YAML is much richer, I would start with either properties or XML.

Access logs from grails plugins

From time to time we like everyone else like to use plugins. Unfortunately they are not always documented all that well. Sometimes you get lucky and find OH DEBUGGING LOG's have been included.
How do you turn on logging for the plugins?
If the plugin is packaged org.plugin.special and the following is our logging setup, how do we add it?
log4j = {
appenders{
rollingFile name: "myAppender", maxFileSize: 1024, file:'/development/log/eightstates.log'
console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n'), threshold: org.apache.log4j.Level.DEBUG
}
debug myAppender: [
'grails.app.controllers.come.example.eightstates',
'grails.app.domain.come.example.eightstates',
'grails.app.services.come.example.eightstates',
'grails.app.taglib.come.example.eightstates',
'grails.app.conf.come.example.eightstates',
'grails.app.filters.come.example.eightstates',
'grails.app.controllers.org.grails.paypal']
}
I think the reason there's not a single logger for plugins is because it's dependent on the artefacts used in the plugin. For example if the plugin uses a controller, then the logger for that will be different than the one used in the plugin's service, and so forth. Unless the plugin offers its own hooks to enable/disable logging, I think your best bet is to enable each artefact individually (which may take a while). I'm not 100% sure, but that's the experience I've had.
This thread talks about logging for the Resources plugin, if that helps at all.

Modifying Grails apps post deployment

I'm investigating Grails vs. other Agile web frameworks, and one key use case I'm trying to support is the ability to modify controllers and install plugins post deployment. It appears that this isn't possible with Grails, but I want to make sure before I write it off.
As far as modifying controllers goes, it would be sufficient if the Groovlet behavior existed (compile-on-demand).
As far as plugin installs go, I understand this may be a long shot, but I thought I'd check to be sure.
For your information, I need this because I work on a product that requires a little site-specific customization, such as adding validation of simple meta-data, integrating with customer security environments, and maybe even including new controllers/pages quickly.
Out of the box, no, grails doesn't really support what you want. There may be ways to customize it but I've never looked into it. A PHP framework might be more of your ally since there is no real deployment process other than copying PHP files to a location.
That said, I personally would prefer a strict set of deployment policies. And honestly, deploying changes with Grails is as simple as running the 'grails war' command and copying that war to your servlet container. The site's downtime is negligible and if you have multiple web servers with a load-balancer, your customers should never see down time due to deployments.
Although it's not recommended for complex coding; You could execute groovy code from a string that you could store in database or a file on the fly at run time:
check out Groovy template engine:
http://groovy.codehaus.org/Groovy+Templates
but even then, you are still limited on what you can do or can't do let alone debugging will lack. you may want to consider an interpreted language; few to mention PHP/Perl/Coldfusion.

Resources