Log4J failover appender with HTTP appender - log4j

So I am using the failoverappender with as primary a HTTP appender. The FailoverAppender docs state:
The FailoverAppender will capture exceptions in an Appender and then route the event to a different appender.
I could not find any documentation however when the HTTPappender will actually throw an exception. So what I was wondering is if my HTTP post request returns a 4XX or 5XX code will this actually throw a log4j exception and activate the failover?

Yes, if a 4xx or 5xx status code is returned, the failover appender will be used.
Which exceptions are thrown by HttpAppender depend upon the implementation of HttpManager in use. Right now the HttpURLConnectionManager is hardcoded into Log4j, which relies upon your system's implementation of HttpURLConnection implementation.
A 4xx or 5xx status code is one of the reasons the standard HttpURLConnection in OpenJDK throws an exception (cf. source code).

Related

How do I register 400 errors in Azure Function Apps as failures in Application Insights?

I want to treat 4xx HTTP responses from a function app (e.g. a 400 response after sending a HTTP request to my function app) as failures in application insights. The function app is being called by another service I control so a 4xx response probably means an implementation error and so I'd like to capture that to ultimately run an alert on it (so I can get an email instead of checking into Azure everytime).
If possible, I'd like it to appear here:
If not, are there any alternative approaches that might fit my use case?
Unless an unhandled exception occurs the function runtime will mark the invocation as succesful, whether the status code is actually denoting an error or not. Since this behavior is defined by the runtime there are 2 things you can do: throw an exception in the code of the function and/or remove exception handling so the invocation is marked as not succesful.
Since you ultimately want to create an alert, you better alert on this specific http status code using a "Custom log search" alert
requests
| where toint(resultCode) >= 400

Spring integration: propagate headers to 'errorChannel'

Is there a way to configure Spring Integration channels such that in case of uncaught exceptions, the headers at the time of exception (if available) are published to the errorChannel along with the exception object?
Right now, I can subscribe to the 'errorChannel' and adds handling code there which is extremely useful. But in errorChannel, I can only get the exception; headers from the original channel are lost. I tried looking at the reference here (https://docs.spring.io/spring-integration/reference/htmlsingle/#namespace-errorhandler) but no luck.
The ErrorMessage payload is a MessagingException with 2 properties cause and failedMessage. The headers are available on the latter.

Can built-in logging messages be turned off?

Once logging is configured with
LogManager.LogFactory = new Log4NetFactory(configureLog4Net: true);
it can be used anywhere with
ILog log = LogManager.GetLogger("foo);
log.Error("foo");
I get it. The problem is that Service Stack uses the same logger for various built-in internal messages. For example, if request is submitted for a non-existing route, Service Stack logs "ServiceStack.Host.Handlers.NotFoundHttpHandler - ::1 Request not found:".
Is there a way to disable or turn off those internal messages?
If you're using Log4Net you should be able to filter Log messages by type, otherwise some of ServiceStack's internal logging can be controlled in your AppHost by overriding:
public override void OnLogError(Type type, string message, Exception innerEx=null)
{
if (!SuppressLogs(type))
base.OnLogError(type, message, innerEx);
}
I've also just changed NotFoundHttpHandler to route messages to route error messages to OnLogError() from this commit so you'll be able to suppress messages by overriding the above method.
This change is available from v4.0.61 that's now available on MyGet.

Can I somehow get a backtrace of a message in Spring Integration?

When, for example, an exception occurres in the middle of a spring integration flow, is there any way to get a path the message have traveled before the crash happend?
The message tracks its path only if #EnableMessageHistory is switched on.
Independently of error handling, Spring Integration always wraps any exception to the MessagingException which has failedMessage property.
Getting that message and analizing its MessageHistory.HEADER_NAME you get the path before an exception.

Use Asynchronous appender with JMS appender in log4j

I want to know more details about AsyncAppender
lyk
Can we control retries if attached appender is not working?
How does it handle error if attached appender encounters the error
N how can I remove attached appender from async appender....
As you know the AsyncAppender is just a wrapper for other appenders. When you create an AsyncAppender you have attach your "real" appenders to it.
The AsyncAppender will buffer your log messages until it has reached your configured limit and publish those log message to the attached appenders all at once.
From the code for AsyncAppender, it is looks like when the buffer is full it simply calls the doAppend method for each attached appender (simple for loop through all appenders). It would be up to the attached appenders to handle error conditions and retries.
I suggest implementing a custom appender by extending SkeletonAppender and handling everything yourself in the methods you override.
To answer your last question, AsyncAppender has a removeAppender method:
public void removeAppender(final Appender appender) {

Resources