Skip to content

Receiver reference

goodsign edited this page Jun 1, 2016 · 38 revisions

File writer

Function: Writes received messages to a file

Element name: file

Allowed attributes:

  • formatid - format that will be used by this receiver
  • path - path to the log file

Example:

<seelog>
    <outputs>
        <file path="log.log"/>
    </outputs>
</seelog>

Important:

  • Do not use any special symbols that are not allowed in filenames.
  • Do not use the same file in multi-process environment to avoid log inconsistency.

Console writer

Function: writes received messages to std out

Element name: Console

Allowed attributes:

  • formatid - format that will be used by this receiver

Example:

<seelog>
    <outputs>
        <console/>
    </outputs>
</seelog>

Rolling file writer (or "Rotation file writer")

Function: Writes received messages to a file, until date changes or file exceeds a specified limit. After that the current log file is renamed and writer starts to log into a new file. If you roll by size, you can set a limit for such renamed files count, if you want, and then the rolling writer would delete older ones when the files count exceed the specified limit.

Element name: rollingfile

Allowed attributes:

  • formatid - format that will be used by this receiver
  • filename - path to the log file. On creation, this path is split into folder path and actual file name. The latter will be used as a common part for all files, that act in rolling:
    • In case of 'date' rolling, the file names will be formed this way: filename.DATE_PATTERN. For example (if fullname flag is not set, see below): app.log, app.log.11.Aug.14, app.log.11.Aug.15, ...

    • In case of 'size' rolling, the file names will be formed this way: "filename.#". For example: app.log, app.log.1, app.log.2, app.log.3, ...

  • type - rotation type: "date" or "size"
  • namemode - naming mode of rolled files. Possible values: "postfix", "prefix". If set to "postfix", rolled files look like 'file.log.1', 'file.log.02.01.2006'. If set to 'prefix': '1.file.log', '02.01.2006.file.log'. Default is 'postfix'.
  • maxrolls - Maximal count of renamed files. When this limit is exceeded, older rolls are removed. Should be >= zero. NOTE: Before version 2.3 this attribute was not applicable to the 'date' rolling writer.
  • archivetype - an attribute used to specify the type of the archive where old rolls are stored instead of removal. Possible values: "none", "zip", "gzip". If set to "none", no archivation is performed (old rolls are just deleted).
  • archiveexploded - an attribute used to specify whether logs should be exploded or grouped inside the same archive file.
  • archivepath - an attribute used when archivetype is not set to "none". Specifies the path of the archive where old rolls are stored.

Attributes, allowed with 'size' type:

  • maxsize - This is the size limit (in bytes) exceeding which results in a roll.

Attributes, allowed with 'date' type:

  • datepattern - This is the pattern that would be used in 'time.LocalTime().Format' to form a file name. The "date" (actually, this means both date & time) rolling occurs when 'time.LocalTime().Format(rollFileWriter.datePattern)' returns something different than the current file name. This means that you create daily rotation using a format with a day identifier like "02.01.2006". Or you can create an hourly rotation using a format with an hour identifier like "02.01.2006.15".
  • fullname - a boolean attribute that affects the current file name. If set to "true", then current file name will use the same naming convention as the roll names. For example, log files list will look like app.log.11.Aug.13, app.log.11.Aug.14, app.log.11.Aug.15, ... instead of app.log, app.log.11.Aug.14, app.log.11.Aug.15, .... Default is "false".

Important:

  • Do not use any special symbols that are not allowed in filenames.
  • Do not use the same file in multi-process environment to avoid log inconsistency.

Example:

<seelog>
	<outputs>
		<rollingfile type="size" filename="logs/roll.log" maxsize="1000" maxrolls="5" />
	</outputs>
</seelog>
<seelog>
    <outputs>
        <rollingfile type="date" filename="logs/roll.log" datepattern="02.01.2006" maxrolls="7" />
    </outputs>
</seelog>

Buffered writer

Function: Acts like a buffer wrapping other writer. Buffered writer stores data in memory and flushes it every flush period or when buffer is full.

Element name: buffered

Allowed attributes:

  • formatid - format that will be used by this receiver
  • size - buffer size (in bytes)
  • flushperiod - interval between buffer flushes (in milliseconds)

Example:

<seelog>
    <outputs>
        <buffered size="10000" flushperiod="1000">
            <file path="bufFile.log"/>
        </buffered>
    </outputs>
</seelog>
<seelog>
    <outputs>
        <buffered size="10000" flushperiod="1000" formatid="someFormat">
            <rollingfile type="date" filename="logs/roll.log" datepattern="02.01.2006" />
        </buffered>
    </outputs>
    <formats>
        ...
    </formats>
</seelog>

NOTE: This writer accumulates data written using a specific format and then flushes it into the inner writer. So inner writers couldn't have its own format: set 'formatid' only for buffered element, like in the last example.

SMTP writer

Function: Sends emails to the specified recipients using a password-protected (but generally unsecured) email account at a given post server.

Element name: smtp

Allowed attributes:

  • senderaddress - email address of the sender
  • sendername - name of the sender
  • hostname - host name of a post server (typically - mail.XXX.YYY)
  • hostport - TCP port of the post server (typically - 587)
  • username - user name used to login to the post server
  • password - password to the post server
  • subject - subject of the email

Subelement: recipient

Allowed attributes:

  • address - email address of the recipient (who receives messages from notifiers)

Subelement: header

Allowed attributes:

  • name - name of the header
  • value - value of the header

Subelement: cacertdirpath

Allowed attributes:

  • path - path to a directory with PEM certificate files.

Example:

<seelog>
  <outputs>
   <smtp 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>
  </outputs>
 </seelog>
<seelog>
  <outputs>
   <filter levels="error,critical">
    <smtp senderaddress="nns@none.org" sendername="ANS" hostname="mail.none.org" hostport="587" username="nns" password="123" subject="test">
     <cacertdirpath path="cacdp1"/>
     <recipient address="hans-meier@none.com"/>
     <header name="Priority" value="Urgent" />
     <header name="Importance" value="high" />
     <header name="Sensitivity" value="Company-Confidential" />
     <header name="Auto-Submitted" value="auto-generated" />
    </smtp>
   </filter>
  </outputs>
 </seelog>

NOTE 1: Look at the first above example to get an idea of how to use SMTP writer. Keep in mind that email noreply-notification-service@none.org must not be considered as security reliable. It's potentially exposed to hacking attacks due to explicit password publication in configs and we strongly recommend you not to use personal or corporate post accounts for SMTP writer. The best practice suggests dedicating an isolated post account especially for email notification service.

NOTE 2: The second example demonstrates the most sensible way to use this writer - notifications from the application on (rare) extraordinary situations. Technically, you can set other filter levels, yet get ready for being flooded with diagnostic emails.

Conn writer

Function: Writes received messages to a network connection.

Element name: conn

Allowed attributes:

  • formatid - format that will be used by this receiver
  • net - network ( "tcp", "udp", "tcp4", "udp4", ... )
  • addr - network address ( ":1000", "127.0.0.1:8888", ... )
  • reconnectonmsg - If true connection will be opened on each write otherwise on first write. Default - false.
  • usetls - if true, TLS will be used.
  • insecureskipverify - sets the InsecureSkipVerify flag of the tls.Config. Use it if useTLS is set.

Example:

<seelog type="sync">
	<outputs>
		<conn net="tcp" addr=":8888" />
	</outputs>
</seelog>
<outputs>
  <conn formatid="syslog" net="tcp4" addr="server.address:5514" tls="true" insecureskipverify="true" />
</outputs>
<formats>
  <format id="syslog" format="%CustomSyslogHeader(20) %Msg%n"/>
</formats>

For %CustomSyslogHeader example code check the custom formatters section.