I want to implement custom logging in my Snap application so that I can pass my logs as JSON to Logstash / Kibana however I cannot figure out how to override the default logging behaviour.
Reading the code, I'm pretty sure that the logA (A for Access log) method is what is providing this logging format implicitly.
But I'm not sure how to override it. How do you override the custom logging in the snap framework? Is it impossible? Will I need to raise a PR? Cheers.
I have asked the Snap Core team if this was possible and the answer is: no, you cannot configure custom logging. Raised a feature request as a result which you can view here.
Related
I've found myself in an interesting position. I currently use the latest Unity container, I'm on asp.net core 2.2, and I use application insights. As such, I have configured DI in my web app to use unity instead of the out of the box DI provider in core. I also use Application Insights and use the IWebHostBuilder.UseApplicationInsights extension to spin up AI for my app.
With all this in mind, I have a piece of code whose constructor takes in IHttpContextAccessor so I can access the HttpContext. It was working great. Then, I had another small app that I was trying to reuse the functionality, and the HttpContext was null coming from IHttpContextAccessor. With a bunch of guess, test, revise, I found that IWebHostBuilder.UseApplicationInsights seems to initialize that Request property (HttpContext) on IHttpContextAccessor. If I commented out that AI extension, I would get null; uncomment it, it worked.
I've started to look through the AI code to figure out what exactly they're doing, but honestly, with all the dependencies and pipelines and all that, it's a pretty daunting task. I was hoping someone could point out where/how AI is doing this so my code doesn't NEED AI in order to work. All help would be incredibly awesome.
Use AddHttpContextAccessor extension to add it to DI. HttpContextAccessor is not added by default due to performance impact.
services.AddHttpContextAccessor();
After some struggle, and hoping this post would enlighten me on the AI ask, I found that I didn't need to replicate the AI mechanism, if there's even one at all.
Originally, I was accessing the IHttpContextAccessor via code in the view (Razor). I have an abstract factory pattern I was using to instantiate IHttpContextAccessor via Unity (this pattern came over from my .Net Frame work days). Once I moved that code back to the controller and used proper .net core DI to get the dependency via the constructor, everything started working.
There must be something there I'm missing, but I have the code working so I'm happy. If someone could shed light on why one way works vs the other, I'd be happy to hear it.
When you enable application insights by calling .UseApplicationInsights(), it adds HttpContextAccessor. There are many components in ApplicationInsights which require HttpContextAccessor injected to it. eg: ClientIpHeaderTelemetryInitializer.
This is the exact line where this is occuring:
https://github.com/Microsoft/ApplicationInsights-aspnetcore/blob/develop/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs#L137
Short: Is there any way to add a custom ITelemetryInitializer to an AzureFunction application?
Long:
After successfully integrating our AzureFunction application with ApplicationInsights and thoroughly instrumenting our code, it became evident really quickly that we'd need to correlate the various Trace and Request telemetry together. To do this we wanted to reuse a custom property we write to all trace logs called a SessionId.
A quick search yielded this SO post and this Docs article. The problem is that these articles assume I have access to some startup event or to the ApplicationInsights.config file on the server. I could be wrong but I don't believe I have access to either one of these.
So my question is, how do I do this with AzureFunctions?
No, it's not possible to customize that. There is work in progress to allow that, but it's not there yet.
You can see more details on these Github issues
application insights integration - ITelemetryInitializer doesn't have any effects #1416
Unable to access TelemetryConfiguration in DefaultTelemetryClientFactory (App Insights) #1556
EDIT:
It's possible in azure function v2.
There was a question on stackoverflow with problem here:
Custom Application Insight TelemetryInitializer using Azure Function v2
The problem was solved and from version Microsoft.Net.Sdk.Functions 1.0.25 all works fine, more here:
https://github.com/Azure/azure-functions-host/issues/3731#issuecomment-465252591
One abhorrent solution I came up with is to reflect into the ILogger that gets passed to the function to get at the ILogger array it hides inside. Then find the ApplicationInsightsLogger ILogger and reflect harder to pull out the TelemetryClient it uses. Once you get this you can merely set the SessionId property on the client's Context.
This works "great" however not only do I now have reflection in my code I had to downgrade the version of ApplicationInsights package I was using to get the type casting to stick.
Looking forward to better support in the future.
I want to override methods of LayoutImpl in Liferay 7. I tried with service wrapper but there is no option for this class in the Service Name category.
How can I achieve that? Do I need ModelListener for this?
Hint: A service wrapper is used to wrap services. Services in Liferay are usually named ...Service, like LayoutLocalService.
Conclusion: The class LayoutImpl is no service - thats why you can't wrap it with a service wrapper.
You could wrap LayoutLocalService in a service wrapper, wrap the return values in your LayoutWrapper and unwrap the parameters. But that is troublesome and will prevent Liferay upgrades.
If you want to override LayoutImpl for fixing bugs - you should use an Ext Plugin for that.
A ModelListener can only change the content during updates of an article, not the implementation - I don't think that this will help here.
I am writing my own custom mediator. In my custom mediator, I use log4j to log the process.. But I am facing difficulties now when deploy the custom mediator in WSO2. What I want is the log in my custom mediator will be written in the "wso2carbon.log". But unfortunately I still have no clue how to do that. Do I need to configure the log4j.properties here? or do I need to implement or extends something in my custom mediator? Thanks :)
Yes this can also be done by adding the package name along with log type needed in the log4j.properties. Doing it through the management console is also an option and you can refer http://docs.wso2.org/display/ESB470/Setting+Up+Logging to get an idea on how to do it.
I solve this using the Management Console in WSO2. In my custom mediator I use the 'info' level, and in WSO2 I think the custom mediator will have the default 'error' level. So I change the level to 'info' level, and the log is shown in the wso2 log file :)
Is there a way to get Ninject to log out what it is doing?
In particular I'd like to see when objects are being created. As I have a mix of transient and singleton objects it'd be very useful for me during debug to be able to see how many instances of each are being created so that I can fix object scopes where needed.
EDIT: N.B. I'm looking at Ninject 2 as found at http://github.com/ninject/ninject
If you look at the new web site you will see a list of extensions. 2.0 RTM is out and the extensions are being released one at a time, but you can still user them. The logging extension is here and you can track the number with a static object and provide a lambda expression to increment it in .OnActivation(...) during binding.
v1.x answer: Yes, via log adapters for a.o. log4net and NLog - see http://mhinze.com/logging-with-ninject/
[in response to comment] EDIT: v2.0 Beta answer: No:-
From Ninject 2 Reaches Beta!
Things that were in Ninject 1.x that are not in Ninject 2:
Logging infrastructure: Cut because it wasn’t really useful anyway. Ninject doesn’t generate logging messages of its own anymore, but I’m looking into alternative sources of introspection.
...