Need help with captainslog?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

131 Stars 18 Forks Mozilla Public License 2.0 192 Commits 1 Opened issues


A Syslog Protocol Parser

Services available


Need anything else?

Contributors list

captainslog Build Status Doc Status

Construct, emit, and parse Syslog messages.


Create a captainslog.SyslogMsg from RF3164 bytes:

b := []byte("<191>2006-01-02T15:04:05.999999-07:00 test: engage\n")
msg, err := captainslog.NewSyslogMsgFromBytes(b)
if err != nil {

Create a captainslog.SyslogMsg by setting its fields:

msg := captainslog.NewSyslogMsg()

msgTime, err := time.Parse("2006 Jan 02 15:04:05", "2017 Aug 15 16:18:34") if err != nil { t.Error(err) }

msg.SetTime(msgTime) msg.SetProgram("myprogram") msg.SetPid("12") msg.SetHost("")

captainslog.NewSyslogMsg accepts the following functional options (note: these may also be passed to SyslogMsg.Bytes() and SyslogMsg.String):

captainslog.OptionUseLocalFormat tells SyslogMsg.String() and SyslogMsg.Byte() to format the message to be compatible with writing to /dev/log rather than over the wire.

captainslog.OptionUseRemoteFormat tells SyslogMsg.String() and SyslogMsg.Byte() to use wire format for the message instead of local format.

Serialize a captainslog.SyslogMsg to RFC3164 bytes:

b := msg.Bytes()

Create a captainslog.Parser and parse a message:

p := captainslog.NewParser()
msg, err := p.ParseBytes([]byte(line)

Both captainslog.NewSyslogMsgFromBytes and captainslog.NewParser accept the following functional arguments:

captainslog.OptionNoHostname sets the parser to not expect the hostname as part of the syslog message, and instead ask the host for its hostname.

captainslog.OptionDontParseJSON sets the parser to not parse JSON in the content field of the message. A subsequent call to SyslogMsg.String() or SyslogMsg.Bytes() will then use SyslogMsg.Content for the content field, unless SyslogMsg.JSONValues have been added since the message was originally parsed. If SyslogMsg.JSONValues have been added, the call to SyslogMsg.String() or SyslogMsg.Bytes() will then parse the JSON, and merge the results with the keys in SyslogMsg.JSONVaues.

captainslog.OptionUseGJSONParser uses the tidwall/gjson parser to parse JSON in the content field of the message. This may improve parsing performance.

captainslog.OptionLocation is a helper function to configure the parser to parse time in the given timezone, If the parsed time contains a valid timezone identifier this takes precedence. Default timezone is UTC.

Contibution Guidelines

We use the Collective Code Construction Contract for the development of captainslog. For details, see


Copyright 2016 DigitalOcean

Captainslog is released under the Mozilla Public License, version 2.0

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.