JBoss 6.0 M3 and Log4j logging - jboss6.x

I'm trying to have application specific logging plus the usual server logs seperately. I have specified 2 in the jboss-logging.xml, one for my app and the other one is usual "server.log" file.
Issue is, both of the log files are getting created and logged at the same time. Can any one help me, what is the change i need to make to log ONLY application specific logs in my logfile?

I fixed this issue. I was defining my application's handler on the section in jboss-logging.xml.Plus i was defining a logger category for my app. The fix was, i removed my application's handler reference from <root-handler> section and hold just the logger category for my app as below:
<logger category="com.X.Y.logger">
<level name="DEBUG"/>
<handlers>
<handler-ref name="myApp"/>
</handlers>
</logger>

Related

Logging with applicationinsights in spring boot app

We are using spring boot to send metrics to app insight we are using applicationinsights-logging-log4j2.
Below are the appenders we are using in logj2-spring.xml
*
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{MM-dd-yyyy'T'HH:mm:ss.SSS,UTC} %correlationId [%thread] %-5level %logger{36}- %msg%n"/>
</Console>
<ApplicationInsightsAppender name="aiAppender">
</ApplicationInsightsAppender>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console" />
<AppenderRef ref="aiAppender" />
</Root>
</Loggers>
We are seeing the logs in app insight search screen however i have few questions.
Is there a way to define a custom info in logging like correlationId(guid used to track a flow uniquely) and send it to AI just like we are appending in console logs.
Is there anything like pattern we can define for AI.
Is there a use of console appender and logging to console if we are logging to AI.
You can create a class that will extend the OncePerRequestFilter, and in that class generate one Id using UUID generator and set this UUID in variable, let's say RequestId.
And then write MDC.put('requestid', RequestId).
OncePerRequestFilter class is executed with every HTTP request, you won't be required to call the class extending it explicitly, and MDC.put('requestid', RequestId) will be added as external property in your application insight log.
This is just a workaround for correlationid though it is providing us a same feature, that we can aggregate a log. Whatever requestid is being generated, you can retrieve that and then use it application insight to see logs for that request.
I believe console appender is still helpful, because I. AI we can see loga after at least 4 to 5 mins, so for real time debugging console logs are helpful. Though you can. Configure what type of logs you want to see in console and what you wanna sent to ai.

How to log HTTP requests sent by ODataQueryBuilder API / VDM API?

Using latest version of Java SAP Cloud SDK
We have some code which uses ODataQueryBuilder API and VDM API as well. We want to log the HTTP requests that are being sent by these API's. We want to log whole of the HTTP request - headers, body everything. Please note that our application is running on SAP Cloud Platform's Cloud Foundry PAAS offering and using cf set-logging-level doesn't seem to work.
I've been using this Java arg when debugging my requests, but I've been doing it locally.
-Dorg.slf4j.simpleLogger.log.org.apache.http.wire=debug
If you can pass it withing CF environment I think you should start seeing all the payloads. I'll research a bit more to provide a better guidance if this won't work for you.
For applications deployed on SCP CF, there are different setups for which recommend other logging practices. The goal is to configure individual log levels for specific packages of your application and third-party dependencies, e.g. SAP Cloud SDK or SAP Service SDK or Apache HTTP components.
TomEE based application:
Edit the manifest.yml to include the following env entry for environment variable:
SET_LOGGING_LEVEL: '{ROOT: INFO, com.sap.cloud.sdk: INFO, org.apache.http.wire: DEBUG}'
Feel free to customize.
Spring Boot based application:
We expect the logback framework.
Edit/Create the file: application/src/main/resources/logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProfile name="!cloud">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<root level="INFO"/>
<logger name="org.springframework.web" level="INFO"/>
</springProfile>
<springProfile name="cloud">
<appender name="STDOUT-JSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="com.sap.hcp.cf.logback.encoder.JsonEncoder"/>
</appender>
<logger name="org.springframework.web" level="INFO"/>
<logger name="com.sap.cloud.sdk" level="INFO"/>
<logger name="org.apache.http.wire" level="DEBUG"/>
<root level="INFO">
<appender-ref ref="STDOUT-JSON"/>
</root>
</springProfile>
</configuration>
Feel free to customize.
Notice the different profile settings. Make sure the cloud profile is active for deployed applications. Edit the manifest.yml to include the following env entry for environment variable:
SPRING_PROFILES_ACTIVE: 'cloud'

How to see HTTP request details that Apache HttpClient sent out [duplicate]

For debugging purposes, I'd like to see the raw request that is going to be sent. Is there a way to get this without a HTTP monitor directly from the API of HttpPost or HttpClient?
I found some "almost" duplicate questions, but not for this particular one
You can set some environment variables for Apache HttpClient (example tested for 4.3.2).
System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG");
There are also some more variables for debugging:
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.impl.conn", "DEBUG");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.impl.client", "DEBUG");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.client", "DEBUG");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "DEBUG");
org.apache.http.client.fluent.Request#viaProxy
This method can make your request pass through proxy server, so your can launch a local proxy server, for example Fiddler, so this debugging proxy can show the details of http request and response.
Try enabling DEBUG mode in your logging configurations, if you're using log4j you can add this to the log4j.xml file of your project
<root>
<priority value="DEBUG" />
<appender-ref ref="FILE" />
</root>
You will have the full request headers, params, body, etc, logged in your logs files.
log4j2 and/or slf4j solution
For everybody using log4j2 and/or slf4j all the mentioned solutions didn't work.
I added the following to my maven pom:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.30</version>
</dependency>
Add a log4j2.xml file / or use your existing one and add:
<Logger name="org.apache.http">
<Level>DEBUG</Level>
</Logger>
Of course for a valid log4j2.xml configuration you need some appenders defined etc. A simple example can be found here
Try this:
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(url);
method.setParameter(...., ....);
to retrieve the URI
System.out.println("getUri: " + method.getURI());
to retrieve the parameters in POST
method.getRequestEntity().writeRequest(System.out);

How do I prevent logging of 404 Not Found exceptions?

I'm using ServiceStack and ServiceStack.Logging.Log4Net. With the minimum config in my AppHost file:
log4net.Config.XmlConfigurator.Configure();
LogManager.LogFactory = new Log4NetFactory(true);
Request handler not found exceptions (i.e. no route was matched) are magically picked up and logged. I don't want to log these exceptions, but I can't figure out how to exclude them.
I've tried setting a custom exception handler:
ExceptionHandler = _appExceptionLogger.OnAppHostException;
but it doesn't appear to get hit for these exceptions.
So I searched in the ServiceStack source code for the string that was being logged and found that it was being logged by a NotFoundHttpHandler class
This means that I can override the logging behaviour by adding a custom logger to my log4net config:
ServiceStack v3:
<logger name="ServiceStack.WebHost.Endpoints.Support.NotFoundHttpHandler">
<level value="OFF" />
</logger>
ServiceStack v4:
<logger name="ServiceStack.Host.Handlers.NotFoundHttpHandler">
<level value="OFF" />
</logger>

log4net config settings

I am into the development of a core dll where I have a class library.I want to use log4net to enable logging for exceptions. I have an app.config file in the class library where i have given the settings for the log4net.However when I test the class library the log4net does'nt create logs until i add the app.config in the calling project inspite of the fact that i had added [assembly: log4net.Config.XmlConfigurator(Watch = true)] in the class libary's assemblyinfo.cs and I am using log4net.ILog logger = log4net.LogManager.GetLogger(typeof(ErrorHandler)) where ErrorHandler is the name of my class library's class where log4net's calling functions are handled.Any ideas on what is going wrong?
Secondly, what I want to acheive is the users of my dll will just pass the location where they want to create logs and whether they want to create logs in event viewer or log files from their app.config? They will not handle any other setting of log4net.
Any suggestions or code snippets for the first issue and the second problem?
Only the "main" app.config is active for a .Net application. Your library config file is simply ignored. Either you transfer your settings to the main config file or you use an external config file for log4net. You configure it then for instance like this (assuming you call it log4net.config):
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
Please note that the structure of the config file is a bit different:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="YourAppender" type="..." >
....
</appender>
<root>
<level value="ALL" />
<appender-ref ref="YourAppender" />
</root>
</log4net>
As for your second problem: I am not sure how flexible this has to be. Is it just switching from file appender to event log appender? Depending on your answer you may consider two prepare to configuration files (e.g. file.log4net and eventlog.log4net) and read the configuration as needed (in that case you cannot use the attribute: you call the Configure() method directly) or if your requirements are more complex you might even end up configuring log4net programatically.

Resources