Skip to content

Dispatchers and receivers

goodsign edited this page Nov 12, 2014 · 29 revisions

The concept

Receivers

We use 'receiver' term for back-end byte receivers, like log files, network channels, etc.

Dispatchers

We use 'dispatcher' term for intermediate elements which send messages to multiple underlying receivers/dispatchers.

Example

The main goal of making dispatcher/receiver configurations is to create different groups with common format options or allowed log levels. For example, let's create an example config:

<seelog>
    <outputs>
        <splitter formatid="common">
            <console/>
            <file path="file.log"/>
            <conn addr="192.168.0.2:8123"/>
        </splitter>
        <filter levels="critical">
            <file path="critical.log" formatid="critical"/>
            <smtp formatid="criticalemail" senderaddress="noreply-notification-service@none.org" sendername="Automatic notification service" hostname="mail.none.org" hostport="587" username="nns" password="123">
                <recipient address="john-smith@none.com"/>
                <recipient address="hans-meier@none.com"/>
            </smtp>
        </filter>
    </outputs>
    <formats>
        <format id="common" format="[%LEV] %Msg"/>
        <format id="critical" format="%Time %Date %RelFile %Func %Msg"/>
        <format id="criticalemail" format="Critical error on our server!\n    %Time %Date %RelFile %Func %Msg \nSent by Seelog"/>
    </formats>
</seelog>

So, here we use a 'splitter' element to group three receivers by format ('common') and other two receivers are grouped by allowed log level using a 'filter'. Note, the top element 'outputs' is a splitter itself, so we could simplify the config:

<seelog>
    <outputs formatid="common">
        <console/>
        <file path="file.log"/>
        <conn addr="192.168.0.2:8123"/>
        <filter levels="critical">
            <file path="critical.log" formatid="critical"/>
            <smtp formatid="criticalemail" senderaddress="noreply-notification-service@none.org" sendername="Automatic notification service" hostname="mail.none.org" hostport="587" username="nns" password="123">
                <recipient address="john-smith@none.com"/>
                <recipient address="hans-meier@none.com"/>
            </smtp>
        </filter>
    </outputs>
    <formats>
        <format id="common" format="[%LEV] %Msg"/>
        <format id="critical" format="%Time %Date %RelFile %Func %Msg"/>
        <format id="criticalemail" format="Critical error on our server!\n    %Time %Date %RelFile %Func %Msg \nSent by Seelog"/>
    </formats>
</seelog>

Formatting

Formats are applied only when writing to a byte-receiver. Dispatchers inherit format identifiers if 'formatid' is not set. Dispatchers and byte-receivers override any inherited formats if 'format id' is set.

Let's use the config from example above:

<seelog>
    <outputs formatid="common">
        <console/>
        <file path="file.log"/>
        <network address="192.168.0.2" port="8123"/>
        <filter levels="critical">
            <file path="critical.log" formatid="critical"/>
            <smtp formatid="criticalemail" senderaddress="noreply-notification-service@none.org" sendername="Automatic notification service" hostname="mail.none.org" hostport="587" username="nns" password="123">
                <recipient address="john-smith@none.com"/>
                <recipient address="hans-meier@none.com"/>
            </smtp>
        </filter>
    </outputs>
    <formats>
        <format id="common" format="[%LEV] %Msg"/>
        <format id="critical" format="%Time %Date %RelFile %Func %Msg"/>
        <format id="criticalemail" format="Critical error on our server!\n    %Time %Date %RelFile %Func %Msg \nSent by Seelog"/>
    </formats>
</seelog>

It demonstrates the inheritance/overriding features. The topmost splitter has 'common' formatid, so all of its children inherit it: console, file, network, and filter. File and smtp receivers that are inside a filter do not inherit it because they override it with their own formatids. If smtp has not had a 'formatid' attribute set, then it would inherit the 'common' formatid from its parent - 'filter' dispatcher.

Demonstration

A working demo of dispatcher/receiver functionality can be found here: outputs

List of dispatchers

Check the Reference

List of receivers

Check the Reference