syslog

package
v0.0.0-...-fdf610b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2018 License: Apache-2.0 Imports: 14 Imported by: 8

Documentation

Index

Constants

View Source
const (
	SyslogdNetwork = ""
	SyslogdRaddr   = ""
	LoggerType     = "LogData"
)
View Source
const DefaultFacility = 1 // for "user-level" messages
View Source
const DefaultVersion = 1 // as per RFC 5424

Variables

This section is empty.

Functions

func GetRequiredEnvVars

func GetRequiredEnvVars() (string, error)

func GetRequiredWriters

func GetRequiredWriters(sys *piazza.SystemConfig, loggerIndex string) (Writer, Writer, error)

Types

type AuditElement

type AuditElement struct {
	Actor  string `json:"actor"`
	Action string `json:"action"`
	Actee  string `json:"actee"` // optional
}

AuditElement represents an SDE for auditing (security-specific of just general).

func (*AuditElement) String

func (ae *AuditElement) String(pen string) string

String builds and returns the RFC5424-style textual representation of an Audit SDE

type DaemonWriter

type DaemonWriter struct {
	// contains filtered or unexported fields
}

A DaemonWriter is a connection to a syslog server.

func Dial

func Dial(network, raddr string) (*DaemonWriter, error)

Dial establishes a connection to a log daemon by connecting to address raddr on the specified network. Each write to the returned writer sends a log message. If network is empty, Dial will connect to the local syslog server.

func (*DaemonWriter) Close

func (w *DaemonWriter) Close() error

Close closes a connection to the syslog daemon.

func (*DaemonWriter) Write

func (w *DaemonWriter) Write(msg string) (err error)

type ElasticWriter

type ElasticWriter struct {
	Esi elasticsearch.IIndex
	// contains filtered or unexported fields
}

ElasticWriter implements the Writer, writing to elasticsearch

func NewElasticWriter

func NewElasticWriter(esi elasticsearch.IIndex, typ string) *ElasticWriter

func (*ElasticWriter) Close

func (w *ElasticWriter) Close() error

Close does nothing but satisfy an interface.

func (*ElasticWriter) CreateIndex

func (w *ElasticWriter) CreateIndex() (bool, error)

func (*ElasticWriter) CreateType

func (w *ElasticWriter) CreateType(mapping string) (bool, error)

func (*ElasticWriter) GetMessages

func (*ElasticWriter) Read

func (w *ElasticWriter) Read(count int) ([]Message, error)

func (*ElasticWriter) SetID

func (w *ElasticWriter) SetID(id string) error

SetID sets the id to write to

func (*ElasticWriter) SetType

func (w *ElasticWriter) SetType(typ string) error

SetType sets the type to write to

func (*ElasticWriter) Write

func (w *ElasticWriter) Write(mssg *Message, async bool) error

Write writes the message to the elasticsearch index, type, id

type FileWriter

type FileWriter struct {
	FileName string
	// contains filtered or unexported fields
}

FileWriter implements the Writer interface, writing to a given file

func (*FileWriter) Close

func (w *FileWriter) Close() error

Close closes the file. The creator of the FileWriter must call this.

func (*FileWriter) Write

func (w *FileWriter) Write(mssg *Message, async bool) error

Write writes the message to the supplied file.

type HttpWriter

type HttpWriter struct {
	// contains filtered or unexported fields
}

HttpWriter implements Writer, by talking to the actual pz-logger service

func NewHttpWriter

func NewHttpWriter(url string, apiKey string) (*HttpWriter, error)

func (*HttpWriter) Close

func (w *HttpWriter) Close() error

func (*HttpWriter) GetMessages

func (w *HttpWriter) GetMessages(
	format *piazza.JsonPagination,
	params *piazza.HttpQueryParams) ([]Message, int, error)

GetMessages is only implemented for HttpWriter as it is most likely the only Writer to be used for reading back data.

func (*HttpWriter) Read

func (w *HttpWriter) Read(count int) ([]Message, error)

func (*HttpWriter) Write

func (w *HttpWriter) Write(mssg *Message, async bool) error

type LocalReaderWriter

type LocalReaderWriter struct {
	// contains filtered or unexported fields
}

MessageWriter implements Reader and Writer, using an array of Messages as the backing store

func (*LocalReaderWriter) Close

func (w *LocalReaderWriter) Close() error

func (*LocalReaderWriter) GetMessages

func (*LocalReaderWriter) Read

func (w *LocalReaderWriter) Read(count int) ([]Message, error)

Read reads messages from the backing array. Will only return as many as are available; asking for too many is not an error.

func (*LocalReaderWriter) Write

func (w *LocalReaderWriter) Write(mssg *Message, async bool) error

Write writes the message to the backing array

type Logger

type Logger struct {
	MinimumSeverity Severity // minimum severity level you want to record

	UseSourceElement bool
	Async            bool
	// contains filtered or unexported fields
}

Logger is the "helper" class that can (should) be used by services to send messages. Client needs to supply the right kind of Writer.

func NewLogger

func NewLogger(logWriter Writer, auditWriter Writer, application string, pen string) *Logger

func (*Logger) Audit

func (logger *Logger) Audit(actor interface{}, action interface{}, actee interface{}, text string, v ...interface{}) error

Audit sends a log message with the audit SDE.

func (*Logger) Debug

func (logger *Logger) Debug(text string, v ...interface{}) error

Debug sends a log message with severity "Debug".

func (*Logger) Error

func (logger *Logger) Error(text string, v ...interface{}) error

Error sends a log message with severity "Error".

func (*Logger) Fatal

func (logger *Logger) Fatal(text string, v ...interface{}) error

Fatal sends a log message with severity "Fatal".

func (*Logger) Info

func (logger *Logger) Info(text string, v ...interface{}) error

Info is just an alternate name for Information

func (*Logger) Information

func (logger *Logger) Information(text string, v ...interface{}) error

Information sends a log message with severity "Informational".

func (*Logger) Metric

func (logger *Logger) Metric(name string, value float64, object string, text string, v ...interface{}) error

Metric sends a log message with the metric SDE.

func (*Logger) Notice

func (logger *Logger) Notice(text string, v ...interface{}) error

Notice sends a log message with severity "Notice".

func (*Logger) Warn

func (logger *Logger) Warn(text string, v ...interface{}) error

Warn is just an alternate name for Warning

func (*Logger) Warning

func (logger *Logger) Warning(text string, v ...interface{}) error

Warning sends a log message with severity "Warning".

type Message

type Message struct {
	Facility    int              `json:"facility"`
	Severity    Severity         `json:"severity"`
	Version     int              `json:"version"`
	TimeStamp   piazza.TimeStamp `json:"timeStamp"` // see note above
	HostName    string           `json:"hostName"`
	Application string           `json:"application"`
	Process     string           `json:"process"`
	MessageID   string           `json:"messageId"`
	AuditData   *AuditElement    `json:"auditData"`
	MetricData  *MetricElement   `json:"metricData"`
	SourceData  *SourceElement   `json:"sourceData"`
	Message     string           `json:"message"`
	// contains filtered or unexported fields
}

Message represents all the fields of a native RFC5424 object, plus our own SDEs.

func NewMessage

func NewMessage(pen string) *Message

NewMessage returns a Message with some of the defaults filled in for you. The returned Message is not valid. To make it pass Message.Validate, you must set Severity, HostName, Application, and Process.

func (*Message) IsSecurityAudit

func (m *Message) IsSecurityAudit() bool

IsSecurityAudit returns true iff the audit action is something we need to formally record as an auidtable event.

func (*Message) String

func (m *Message) String() string

String builds and returns the RFC5424-style textual representation of a Message.

func (*Message) Validate

func (m *Message) Validate() error

Validate checks to see if a Message is well-formed.

type MetricElement

type MetricElement struct {
	Name   string  `json:"name"`
	Value  float64 `json:"value"`
	Object string  `json:"object"`
}

MetricElement represents an SDE for recoridng metrics.

func (*MetricElement) String

func (me *MetricElement) String(pen string) string

String builds and returns the RFC5424-style textual representation of an Metric SDE

type MultiWriter

type MultiWriter struct {
	// contains filtered or unexported fields
}

MultiWriter will write to N different Writers at once. When doing a Write or a Close, we call the function on all of them. If any have failed, we return the error from the first one that failed.

func NewMultiWriter

func NewMultiWriter(ws []Writer) *MultiWriter

func (*MultiWriter) Close

func (mw *MultiWriter) Close() error

func (*MultiWriter) Write

func (mw *MultiWriter) Write(m *Message, async bool) (err error)

type NilWriter

type NilWriter struct {
}

NilWriter doesn't do anything

func (*NilWriter) Close

func (*NilWriter) Close() error

func (*NilWriter) Write

func (*NilWriter) Write(*Message, bool) error

type Reader

type Reader interface {
	Read(count int) ([]Message, error)
	GetMessages(*piazza.JsonPagination, *piazza.HttpQueryParams) ([]Message, int, error)
}

Reader is an interface for reading Messages from some sort of input. count is the number of messages to read: 1 means the latest message, 2 means the two latest messages, etc. The newest message is at the end of the array.

type Severity

type Severity int
const (
	Emergency     Severity = 0 // not used by Piazza
	Alert         Severity = 1 // not used by Piazza
	Fatal         Severity = 2 // called Critical in the spec
	Error         Severity = 3
	Warning       Severity = 4
	Notice        Severity = 5
	Informational Severity = 6
	Debug         Severity = 7
)

func (Severity) Value

func (s Severity) Value() int

type SourceElement

type SourceElement struct {
	File     string `json:"file"`
	Function string `json:"function"`
	Line     int    `json:"line"`
}

SourceElement represents an SDE for tracking the message back to the source code.

func NewSourceElement

func NewSourceElement(skip int) *SourceElement

func (*SourceElement) String

func (se *SourceElement) String(pen string) string

String builds the text string of the SDE

type StderrWriter

type StderrWriter struct {
}

StderrWriter writes messages to STDERR

func (*StderrWriter) Close

func (w *StderrWriter) Close() error

Nothing to close for this writer

func (*StderrWriter) Write

func (w *StderrWriter) Write(mssg *Message, async bool) error

Writes message to STDERR

type StdoutWriter

type StdoutWriter struct {
}

StdoutWriter writes messages to STDOUT

func (*StdoutWriter) Close

func (w *StdoutWriter) Close() error

Nothing to close for this writer

func (*StdoutWriter) Write

func (w *StdoutWriter) Write(mssg *Message, async bool) error

Writes message to STDOUT

type SyslogdWriter

type SyslogdWriter struct {
	// contains filtered or unexported fields
}

SyslogdWriter implements a Writer that writes to the syslogd system service. This will almost certainly not work on Windows, but that is okay because Piazza does not support Windows.

func (*SyslogdWriter) Close

func (w *SyslogdWriter) Close() error

Close closes the underlying network connection.

func (*SyslogdWriter) Write

func (w *SyslogdWriter) Write(mssg *Message, async bool) error

Write writes the message to the OS's syslogd system.

type Writer

type Writer interface {
	Write(*Message, bool) error

	Close() error
	// contains filtered or unexported methods
}

Writer is an interface for writing a Message to some sort of output.

type WriterReader

type WriterReader interface {
	Reader
	Writer
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL