Documentation
¶
Index ¶
- func WithPGAddr(addr string) configValues
- func WithPGDB(d string) configValues
- func WithPGPassword(p string) configValues
- func WithPGUser(u string) configValues
- type LogEntry
- func (l *LogEntry) Fetch(msg logMessage, rid logResourceID, level logLevel, beforeTime *time.Time, ...) ([]LogEntry, error)
- func (l LogEntry) GetLevel() logLevel
- func (l LogEntry) GetMsg() logMessage
- func (l LogEntry) GetRID() logResourceID
- func (l LogEntry) GetTimestamp() time.Time
- func (l *LogEntry) Level(level logLevel) *LogEntry
- func (l *LogEntry) Msg(msg logMessage) *LogEntry
- func (l *LogEntry) RID(rid logResourceID) *LogEntry
- func (l *LogEntry) Timestamp(ts time.Time) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithPGAddr ¶
func WithPGAddr(addr string) configValues
WithPGAddr sets the PostgreSQL connection address. Address should be in the format `host:port`. E.g. `localhost:5432`.
func WithPGPassword ¶
func WithPGPassword(p string) configValues
func WithPGUser ¶
func WithPGUser(u string) configValues
Types ¶
type LogEntry ¶
type LogEntry struct {
// contains filtered or unexported fields
}
LogEntry provides a fluent API for logging. It logs the `message` with the `resourceID`, `level` and `timestamp`.
Only when the `Timestamp` method is called will the log will be entered into the database.
func Init ¶
Init uses functional options pattern to initialize the database connection and create the logs table if it does not already exist. It returns a `LogEntry` object that can be used to log messages which are then saved to the database.
func (*LogEntry) Fetch ¶
func (l *LogEntry) Fetch( msg logMessage, rid logResourceID, level logLevel, beforeTime *time.Time, afterTime *time.Time, ) ([]LogEntry, error)
Fetch is used to fetch log entries from the database. It performs the query to the database based on the arguments provided. If an argument is the default value for the type, that argument is not included in the query string.
`msg` is used to perform a LIKE query on the `message` column.
Fetch returns a slice of LogEntry objects and an error if the query fails.
func (LogEntry) GetLevel ¶
func (l LogEntry) GetLevel() logLevel
GetLevel returns the level of the log entry.
`NB`: It should only be called on an entry returned by the `Fetch` method. Calling `GetLevel` on any other object will result in an undefined behavior.
func (LogEntry) GetMsg ¶
func (l LogEntry) GetMsg() logMessage
GetMsg returns the message of the log entry.
`NB`: It should only be called on an entry returned by the `Fetch` method. Calling `GetMsg` on any other object will result in an undefined behavior.
func (LogEntry) GetRID ¶
func (l LogEntry) GetRID() logResourceID
GetRID returns the resource ID of the log entry.
`NB`: It should only be called on an entry returned by the `Fetch` method. Calling `GetRID` on any other object will result in an undefined behavior.
func (LogEntry) GetTimestamp ¶
GetTimestamp returns the time stamp of the log entry.
`NB`: It should only be called on an entry returned by the `Fetch` method. Calling `GetTimestamp` on any other object will result in an undefined behavior.
func (*LogEntry) Level ¶
Level is used to set the log level of the entry. It takes in a logLevel and returns a LogEntry object.
The log entry is never saved to the database until the `Timestamp` method is called.
func (*LogEntry) Msg ¶
Msg is used to set the message of the log entry. It takes in a `logMessage` and returns a `LogEntry` object.
The log entry is never saved to the database until the `Timestamp` method is called.