Skip to content

dracory/logstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Log Store Open in Gitpod

Tests Status Go Report Card PkgGoDev

Logs messages to a database table.

License

This project is licensed under the GNU General Public License version 3 (GPL-3.0). You can find a copy of the license at https://www.gnu.org/licenses/gpl-3.0.en.html

For commercial use, please use my contact page to obtain a commercial license.

Installation

go get -u github.com/dracory/logstore

Setup

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

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

Usage

logStore.Info("Hello")

// with additional context
logStore.InfoWithContext("Hello", map[string]string{
    "name": "John Doe"
})

Slog

As slog is the now official logger in golang, LogStore provides a SlogHandler.

Logger = *slog.New(logstore.NewSlogHandler(&LogStore))

logger.Info("Hello", "name", "John Doe")

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

2024.09.23 - Added a SlogHandler

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages