logger

package
v0.0.0-...-0117b6e Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package ssmlog is used to initialize ssm functional logger

Package logger is used to initialize the logger(main logger and event logger). This package should be imported once, usually from main, then call GetLogger.

Package log is used to initialize the logger(main logger and event logger). This package should be imported once, usually from main, then call GetLogger.

Package log is used to initialize the logger. This package should be imported once, usually from main, then call GetLogger.

Package log is used to initialize the logger. This package should be imported once.

Index

Constants

View Source
const (
	AmazonAgentStartEvent               = "amazon-ssm-agent.start"          // Amazon core agent start event
	AmazonAgentWorkerStartEvent         = "ssm-agent-worker.start"          // Amazon agent worker start event
	AmazonAgentInProcExecuterStartEvent = "ssm-agent-inproc-executer.start" // Amazon agent inproc executer start event

	AuditSentSuccessFooter = "AuditSent="
	SchemaVersionHeader    = "SchemaVersion="

	// Message types for the event log chunks created
	AgentTelemetryMessage    = "agent_telemetry"     // AgentTelemetryMessage represents message type for number Legacy Agent/Agent Reboot
	AgentUpdateResultMessage = "agent_update_result" // AgentUpdateResultMessage represents message type for number Agent update result

	BytePatternLen = 9 // BytePatternLen represents length of last read byte section in footer of audit file. Considered the audit file max file size to be 999.99MB

	VersionRegexPattern = "^\\d+(\\.\\d+){3}$" // pattern to filter out invalid versions
)
View Source
const (
	LogFile      = "amazon-ssm-agent.log"
	ErrorFile    = "errors.log"
	EventLogFile = "amazon-ssm-agent-audit"
)

Variables

View Source
var (
	AuditFolderName = "audits"
)
View Source
var (
	DefaultLogDir = "/var/log/amazon/ssm"
)
View Source
var DefaultSeelogConfigFilePath = appconfig.SeelogFilePath

DefaultSeelogConfigFilePath specifies the default seelog location The underlying logger is based of https://github.com/cihub/seelog See Seelog documentation to customize the logger

View Source
var PkgMutex = new(sync.RWMutex)

Functions

func DefaultConfig

func DefaultConfig() []byte

func DefaultLogger

func DefaultLogger() log.T

func GetLogConfigBytes

func GetLogConfigBytes() []byte

func GetLogger

func GetLogger(log log.T, seelogConfig string) (logger seelog.LoggerInterface)

GetLogger creates a new logger with the provided config and returns it

func LoadLog

func LoadLog(defaultLogDir string, logFile string, debugStatus string) []byte

func NewSilentLogger

func NewSilentLogger() log.T

NewSilentLogger is a logger that discards messages sent to it. Use this in situations where a function requires a log.T but messages the function sends to it need not be visible to users. contributed by github user chrisnovakovic

func PrintCWConfig

func PrintCWConfig(jsonConfig string, log log.T) string

PrintCWConfig checks if the config file has credentials and returns a string with the credentials removed, for printing

func WriteLastLineFile

func WriteLastLineFile(eventCounter *EventCounter) error

WriteLastLineFile updates the file name with the Audit success status. This should be locked by the caller if called by multiple threads.

Types

type ContextFormatFilter

type ContextFormatFilter struct {
	Context []string
}

ContextFormatFilter is a filter that can add a context to the parameters of a log message.

func (ContextFormatFilter) Filter

func (f ContextFormatFilter) Filter(params ...interface{}) (newParams []interface{})

Filter adds the context at the beginning of the parameter slice.

func (ContextFormatFilter) Filterf

func (f ContextFormatFilter) Filterf(format string, params ...interface{}) (newFormat string, newParams []interface{})

Filterf adds the context in from of the format string.

type DelegateLogger

type DelegateLogger struct {
	BaseLoggerInstance log.BasicT
}

DelegateLogger holds the base logger for logging

type EventCounter

type EventCounter struct {
	AuditFileName  string         // audit file name
	AuditDate      string         // Can be used later. Date to which the audit file belongs to.
	CountMap       map[string]int // count of events found in audit log
	SchemaVersion  string         // schema version from audit file
	AgentVersion   string         // denotes agent version found in the audit log
	LastReadTime   string         // denotes last read time stamp from file
	LastReadByte   int            // denotes last read byte from file
	IsFirstChunk   bool           // denotes first chunk taken from file
	EventChunkType string         // denotes message type used to send to MGS
}

EventCounter contains the audit count, file name and the audit date to be sent to MGS

func GetEventCounter

func GetEventCounter() ([]*EventCounter, error)

GetEventCounter returns the count of the audits in the previous days logs. Returns empty list when an exception is thrown by file handlers

type EventLog

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

Creates events with the appropriate file parameters passed to this instance

func GetEventLog

func GetEventLog(logFilePath string, logFileName string) (eventLog *EventLog)

GetEventLog returns the Event log instance and is called by the SSM Logger during app startup

func (*EventLog) GetAuditFileName

func (e *EventLog) GetAuditFileName() string

GetAuditFileName will return the audit file name without the date pattern

func (*EventLog) GetAuditFilePath

func (e *EventLog) GetAuditFilePath() string

GetAuditFilePath will return the audit file path

func (*EventLog) GetFileSystem

func (e *EventLog) GetFileSystem() filesystem.IFileSystem

GetAuditFilePath will return the file system instance

func (*EventLog) GetTodayAuditFileName

func (e *EventLog) GetTodayAuditFileName() string

GetTodayAuditFileName will return the audit file name of currently used one

type FormatFilter

type FormatFilter interface {

	// Filter modifies parameters that will be passed to log.Debug, log.Info, etc.
	Filter(params ...interface{}) (newParams []interface{})

	// Filter modifies format and/or parameter strings that will be passed to log.Debugf, log.Infof, etc.
	Filterf(format string, params ...interface{}) (newFormat string, newParams []interface{})
}

FormatFilter can modify the format and or parameters to be passed to a logger.

type Wrapper

type Wrapper struct {
	Format      FormatFilter
	M           *sync.RWMutex
	Delegate    *DelegateLogger
	EventLogger *EventLog
}

Wrapper is a logger that can modify the format of a log message before delegating to another logger.

func (*Wrapper) Close

func (w *Wrapper) Close()

Close flushes all the messages in the logger and closes it. It cannot be used after this operation.

func (*Wrapper) Closed

func (w *Wrapper) Closed() bool

Closed checks if logger is closed

func (*Wrapper) Critical

func (w *Wrapper) Critical(v ...interface{}) error

Critical formats message using the default formats for its operands and writes to log with level = Critical

func (*Wrapper) Criticalf

func (w *Wrapper) Criticalf(format string, params ...interface{}) error

Criticalf formats message according to format specifier and writes to log with level = Critical.

func (*Wrapper) Debug

func (w *Wrapper) Debug(v ...interface{})

Debug formats message using the default formats for its operands and writes to log with level = Debug

func (*Wrapper) Debugf

func (w *Wrapper) Debugf(format string, params ...interface{})

Debugf formats message according to format specifier and writes to log with level = Debug.

func (*Wrapper) Error

func (w *Wrapper) Error(v ...interface{}) error

Error formats message using the default formats for its operands and writes to log with level = Error

func (*Wrapper) Errorf

func (w *Wrapper) Errorf(format string, params ...interface{}) error

Errorf formats message according to format specifier and writes to log with level = Error.

func (*Wrapper) Flush

func (w *Wrapper) Flush()

Flush flushes all the messages in the logger.

func (*Wrapper) Info

func (w *Wrapper) Info(v ...interface{})

Info formats message using the default formats for its operands and writes to log with level = Info

func (*Wrapper) Infof

func (w *Wrapper) Infof(format string, params ...interface{})

Infof formats message according to format specifier and writes to log with level = Info.

func (*Wrapper) Log

func (w *Wrapper) Log(i ...interface{})

func (*Wrapper) ReplaceDelegate

func (w *Wrapper) ReplaceDelegate(newLogger log.BasicT)

ReplaceDelegate replaces the delegate logger with a new logger

func (*Wrapper) Trace

func (w *Wrapper) Trace(v ...interface{})

Trace formats message using the default formats for its operands and writes to log with level = Trace

func (*Wrapper) Tracef

func (w *Wrapper) Tracef(format string, params ...interface{})

Tracef formats message according to format specifier and writes to log with level = Trace.

func (*Wrapper) Warn

func (w *Wrapper) Warn(v ...interface{}) error

Warn formats message using the default formats for its operands and writes to log with level = Warn

func (*Wrapper) Warnf

func (w *Wrapper) Warnf(format string, params ...interface{}) error

Warnf formats message according to format specifier and writes to log with level = Warn.

func (*Wrapper) WithContext

func (w *Wrapper) WithContext(context ...string) (contextLogger log.T)

WithContext creates a wrapper logger with context

func (*Wrapper) WriteEvent

func (w *Wrapper) WriteEvent(eventType string, agentVersion string, event string)

WriteEvent creates event in audit log. When blank value passed, will use the version number generated in version package

Jump to

Keyboard shortcuts

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