logstore

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: MIT Imports: 13 Imported by: 1

README

Log Store

Tests Status Go Report Card PkgGoDev

Logs messages to a database table.

Installation

go get -u github.com/gouniverse/logstore

Setup

logStore, err = logstore.NewStore(logstore.NewStoreOptions{
    DB: databaseInstance,
    LogTableName: "log",
    AutomigrateEnabled: true,
})

if err != nil {
    panic(error.Error())
}

Usage

logStore.Info("Hello")

Log Levels

  1. LevelTrace - Something very low level
  2. LevelDebug - Useful debugging information
  3. LevelInfo - Something noteworthy happened!
  4. LevelWarn - You should probably take a look at this
  5. LevelError - Something failed but I'm not quitting
  6. LevelFatal - Bye. Calls os.Exit(1) after logging
  7. LevelPanic - I'm bailing. Calls panic() after logging

Change Log

2023.07.19 - Updated instance creation to use options struct

2022.06.26 - Updated dependencies

2021.12.21 - Added LICENSE

2021.12.21 - Added test badge

2021.12.21 - Added support for DB dialects

2021.12.21 - Removed GORM dependency and moved to the standard library

Documentation

Index

Constants

View Source
const (
	// LevelTrace trace level
	LevelTrace = "trace"
	// LevelDebug debug level
	LevelDebug = "debug"
	// LevelError error level
	LevelError = "error"
	// LevelFatal fatal level
	LevelFatal = "fatal"
	// LevelInfo info level
	LevelInfo = "info"
	// LevelPanic panic level
	LevelPanic = "panic"
	// LevelWarning warning level
	LevelWarning = "warning"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

type Log struct {
	ID      string
	Level   string
	Message string
	Context string
	Time    *time.Time
}

Log type

type NewStoreOptions added in v1.3.0

type NewStoreOptions struct {
	LogTableName       string
	DB                 *sql.DB
	DbDriverName       string
	AutomigrateEnabled bool
	DebugEnabled       bool
}

NewStoreOptions define the options for creating a new session store

type Store

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

Store defines a session store

func NewStore

func NewStore(opts NewStoreOptions) (*Store, error)

NewStore creates a new session store

func (*Store) AutoMigrate

func (st *Store) AutoMigrate() error

AutoMigrate auto migrate

func (*Store) Debug

func (st *Store) Debug(message string) (bool, error)

Debug adds a debug log

func (*Store) DebugWithContext

func (st *Store) DebugWithContext(message string, context interface{}) (bool, error)

DebugWithContext adds a debug log with context data

func (*Store) DriverName

func (st *Store) DriverName(db *sql.DB) string

DriverName finds the driver name from database

func (*Store) EnableDebug

func (st *Store) EnableDebug(debug bool)

EnableDebug - enables the debug option

func (*Store) Error

func (st *Store) Error(message string) (bool, error)

Error adds an error log

func (*Store) ErrorWithContext

func (st *Store) ErrorWithContext(message string, context interface{}) (bool, error)

ErrorWithContext adds an error log with context data

func (*Store) Fatal

func (st *Store) Fatal(message string) (bool, error)

Fatal adds an fatal log and calls os.Exit(1) after logging

func (*Store) FatalWithContext

func (st *Store) FatalWithContext(message string, context interface{}) (bool, error)

FatalWithContext adds a fatal log with context data and calls os.Exit(1) after logging

func (*Store) Info

func (st *Store) Info(message string) (bool, error)

Info adds an info log

func (*Store) InfoWithContext

func (st *Store) InfoWithContext(message string, context interface{}) (bool, error)

InfoWithContext adds an info log with context data

func (*Store) Log

func (st *Store) Log(logEntry *Log) (bool, error)

Log adds a log

func (*Store) Panic

func (st *Store) Panic(message string)

Panic adds an panic log and calls panic(message) after logging

func (*Store) PanicWithContext

func (st *Store) PanicWithContext(message string, context interface{})

PanicWithContext adds a panic log with context data and calls panic(message) after logging

func (*Store) SqlCreateTable

func (st *Store) SqlCreateTable() string

SqlCreateTable returns a SQL string for creating the setting table

func (*Store) Trace

func (st *Store) Trace(message string) (bool, error)

Trace adds a trace log

func (*Store) TraceWithContext

func (st *Store) TraceWithContext(message string, context interface{}) (bool, error)

TraceWithContext adds a trace log with context data

func (*Store) Warn

func (st *Store) Warn(message string) (bool, error)

Warn adds a warn log

func (*Store) WarnWithContext

func (st *Store) WarnWithContext(message string, context interface{}) (bool, error)

WarnWithContext adds a warn log with context data

Jump to

Keyboard shortcuts

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