Spock: console output to log4j / graylog - log4j

We are using the Spock framework for automated testing. The output of the tests (e.g. assert failures etc.) is sent to the console.
I also want to send the output to log4j / graylog, but I just do n't understand how to do that or if that is even possible.
Is Spock using log4j? Or is it sending the output directly to stdout / stderr?

If you don't have a logback configuration you need to add it before you can use logging feature. To setup logback please refer to this article.

Related

Microservice integration with ELK stack as done in jhipster

I want to try ELK stack independently instead of using jhispter console.
I wanted to understand how spring boot microservice is integrated with ligstash.
As I see only jhipster.logstash enabled flag is set in application.yml file. I want to know what is the java file in jhipster framework which integrates application logs with logstash ?
It's LoggingConfiguration.java and it uses this logstash appender library.

log4j conflicts with netty

Just installed log4j and got it working pretty well, but I noticed because netty also uses log4j, im getting all the log messages from netty too. Is there any way I can configure log4j to ignore netty?
also as a side note if theres any way I can configure log4j so I don't have to type
static Logger log = Logger.getLogger(Yourclass.class);
in every class that be great to know too
You can change the log level for io.netty to WARN or ERROR. If you are not familiar with log4j configuration, please read this and this.

monitoring J2EE application deployed in Tomcat using snmp

I am going to write a J2EE application and application will be deployed in Tomcat.
The requirement is that the server and the application must send snmp trap to external NMS.
The details of my application is
J2EE application
Deployed in Tomcat v7
The Server is Redhat Linux 6.2
We need to send trap for all the above 3 (For the application, Tomcat and the linux server).
Can we write our own agent using snmp4j for the above requirement and how will snmp agent know when to send trap to NMS?
Thanks in advance for support.
Yes you can for that you need to extend the logger framework. For Instance you can use logback framework. where you can extend the logging with CustomAppender where you can write snmp-agent code and forward the log as an trap. Moreoever logback has nice and easy way to format, deny log if not necessary other other feature. And you can change the tomcat logging to logback is simple steps. However I'm not sure if you can really send a trap for any issues on linux server. I believe it would be a tedious task. You might look for some syslog server monitoring feature.

Configure log4j to send its logs to Splunk?

I need to send my log4j logs to Splunk. I found several solutions:
To use REST API (e.g. curl -k -u admin:changeme -d "name=/tmp/myfile.log" -d "sourcetype=syslog" https://localhost:8089/servicesNS/admin/search/data/inputs/monitor)
Install Splunk Universal Forwarder
Use log4j appender
such as:
Syslog appender
log4j.appender.splunk=org.apache.log4j.net.SyslogAppender
log4j.appender.splunk.SyslogHost=localhost:8089
log4j.appender.splunk.layout=org.apache.log4j.PatternLayout
log4j.appender.splunk.facility=LOCAL2
log4j.appender.splunk.layout.ConversionPattern=[%p] %t: %m%n
but it seems to me that 3rd solution wouldn't work if splunk server and log are located on separate machines.
2nd solution requires to install additional software
Can anyone propose any other solution?
PS I tried to use opensource java libs. But it didn't give a result.
Check out this great project from one of our community developers #damiendallimore - https://github.com/damiendallimore/SplunkJavaLogging
It provides a number of options for logging directly to Splunk.
It also uses the Splunk Java SDK: http://dev.splunk.com/view/java-sdk/SP-CAAAECN

How to configure log4net for fallback

This is my situation. I have successfully implemented logging to remote syslog using log4net. However, as far as I could test, if syslog IP is not valid, all messages will not log anywhere and no exception is raised. It just does nothing.
Hence, it would be nice to have some sort of fallback. Let's say if writing to syslog fails, write to file or to database.
Is that even possible with log4net? Or would I have to configure it to log to two locations at the same time?
I don't think you can do this by configuration. This issue is open in the log4net feature backlog.
If your application can eat the logging overhead, the easiest solution would be to log to an alternative appender by default.
Alternatively you could try to wrap the appender you're using in a custom appender, and implement the fallback scenario if the syslog appender throws an exception. If it doesn't swallow them silently.
From log4net FAQ:
You can implement the log4net.Appender.IAppender interface to create you own customized appender. We recommend that you extend the log4net.Appender.AppenderSkeleton class rather than starting from scratch. You should implement your custom code in a assembly separate from the log4net assembly.
To get started it is worth looking at the source of the log4net.Appender.TraceAppender as an example of the minimum amount of code required to get an appender working.
Third option would be to look into the source code of your appender and see if you can fork it and do the necessary customizations there.

Resources