Attach and detach listeners to Serilog on the fly? - serilog

Is it possible to add or remove listeners / sinks dynamically using Serilog? I see from the configuration documentation that sinks are determined in the source code by calling WriteTo. I suppose I can create a section in my application startup to determine whether to register a sink or not. But is there something similar to the way ETW publish and subscribe events? For example we can run Perfview to listen to ETW events on the fly.

Related

Log4j2 programmatic modifying current configuration, synchronizing addAppender and addLogger

I want to modify log4j2 configuration after init (which is done with log4j2.xml file), meaning during runtime, and in official docs it says (point 2 in below snippet) that "Modification to the running configuration requires that all the methods being called (addAppender and addLogger) be synchronized."
I don't understand if they meant only those two calls or other calls as well, or if I as a user will need to synchronize the methods, and reason for it is that addLogger() is already Synchronized (implemented in AbstractConfiguration) and addLogger is using a ConcurrentHashMap (for loggerConfigs var), so I see no reason why I need to synchronize these calls.
P.S
I need runtime modification partly for user configuration of messages to be sent to syslog (with host,facility,port of their choice), so I'm adding syslog appenders in runtime. I don't see any other way then programmatic changes.

How to configure Serilog for WCF

I am upgrading our old application for Serilog... One of the existing functionality is ... When log level = ERROR, it will log into local file and send 'WCF' request to the remote server, remote server will update database...
Basically it will log into multiple source(local file, remote database by sending wcf request) if it level is 'ERROR'.
I understand using 'rollingfile' appender to logging into local file.
However, i do not know how to configure 'WCF Service' for Serilog... is there any 'WCF SINK' can help me achieve this?
As of this writing there's no generic sink that makes "WCF" calls... You'd have to build your own sink, implementing the calls you need.
You can see a list of documented sinks in the "Provided Sinks" page on Serilog's wiki, and you can also see available sinks in NuGet.org.

Spring Cloud DataFlow Rabbit Source: how to intercept and enrich messages in a Source

I have been successfully evaluating Spring Cloud DataFlow with a typically simple flow: source | processor | sink.
For deployment there will be multiple sources feeding into this pipeline which I can do using data flow labels. All well and good.
Each source is a different rabbitmq instance and because the processor needs to know where the message came from (because it has to call back to the source system to get further information), the strategy I'd thought of was to enrich each message with header details about the source system which is then transparently passed along to the processor.
Now, I'm well-versed in Spring, Spring Boot and Spring Integration but I cannot find out how to enrich each message in a dataflow source component.
The source component is bound to an org.springframework.cloud.stream.app.rabbit.source.RabbitSourceConfiguration. The source uses the default Source.OUTPUT channel. How do I get hold of each message in the source to enrich it?
My processor component uses some Spring Integration DSL to do some of what it needs to do but then this processor component has both an INPUT and OUTPUT channel by definition. Not so with the RabbitSourceConfiguration source.
So, can this be done?
I think you need a custom MessageListener on the MessageListenerContainer in RabbitSourceConfiguration.
In the RabbitSourceConfiguration you can set a custom ChannelAwareMessageListener (You can possibly extend from MessagingMessageListenerAdapter as well) on the MessageListenerContainer that does what you incline to do.
In the end what worked was subclassing org.springframework.cloud.stream.app.rabbit.source.RabbitSourceConfiguration to:
override public SimpleMessageListenerContainer container() so that I could insert a custom health check before calling super.container(). My business logic enriches each message (see next bullet) with details of where the message came from (note, this is the publisher of the messages and not the rabbit queue). There's a health check needed to validate the additional enriching information (which is provided via configuration) to ensure that messages aren't consumed from the queue and enriched with the wrong information. If the validation fails, the source component fails to start and hence no messages are consumed.
override the creation of the AmqpInboundChannelAdapter bean so that a custom subclass of DefaultAmqpHeaderMapper can be set on the adapter. This custom mapper adds the enriched headers in public Map toHeadersFromRequest(final MessageProperties source).
For me, the inability of stream/dataflow to intercept and modify messages in Source components is problematic. I really shouldn't have to fiddle around with the underlying message broker API in the ways I did. I should be able to do it with e.g. Spring Integration. Indeed I can register a global message interceptor but I cannot change the headers of the message.
This ability would go on my WIBNI (wouldn't it be nice if) list. Perhaps I'll raise a request for this.

How to wrap a JMXClient in a JavaAgent

I want to load a custom JMX Client into a JVM by wrapping the client in a javaagent package and query MBeans locally. My intent is that the JMX Client will periodically query the host application's MBeans or receive notifications. However, since the javaagent is loaded before the main jar (via premain), the host applications's MBeans are not yet available. How should I handle this "chicken before the egg" problem? Are threads appropriate for this? Or is there some other JMX mechanism that would be preferred?
Thank you
Start a loop with a sleep in it until you successfully get the target MBeanServer. If this is the platform MBeanServer, you should get it immediately using ManagementFactory.getPlatformMBeanServer(). Then register a notification listener with the ObjectName defined as MBeanServerDelegate.DELEGATE_NAME. Filter for notifications of the class MBeanServerNotification, with notification types of MBeanServerNotification.REGISTRATION_NOTIFICATION. Your notification listener will get a callback every time a new MBean is registered in the target MBeanServer.

Where to register mediator in puremvc?

Currently I am working on flex using puremvc framework. Actually my question is related to where to register mediator in puremvc framework. One of my colleague is registering mediator in views(components) creationComplete method only (inside view). While my preference is send some notification from creationComplete method which could be handle by some command and command will register mediator. So which one is better approach in terms of best practice ?
Views by themselves can't register mediators. Mediators can register mediators instead. E.g. you have a Panel and a PanelMediator. If you have a ListA and ListB in this panel your PanelMediator can add creation complete event listeners to ListA and ListB. In these listeners you can register mediators like ListAMediator/ListBMediator.
The goal is to make components reusable, so your Views should deal with UI and not with your application core.
I would register your mediators in Commands.
From Best Practices...
To communicate and interact with other
parts of the system, Commands may:
Register, remove or check for the existing registration of Mediators,
Proxies, and Commands.
Send Notifications to be responded to by other Commands or Mediators.
Retrieve and Proxies and Mediators and manipulate them directly.
As mico mentioned, View's should not register their own mediators, and Proxy's should stay tied to their data sources they interface with and nothing else.
I usually have one StartUp notification which gets called right after the base Movieclip receives an added to stage event. This StartUp notification triggers a StartUp command which will register all mediators and proxies needed. Hope this helps.

Resources