create log class, edit fatal-but-not-really logs
This commit is contained in:
parent
8ccf6f242b
commit
e80a6753a5
4 changed files with 66 additions and 8 deletions
58
log/log.go
Normal file
58
log/log.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type (
|
||||
Logger struct {
|
||||
DB *sqlx.DB
|
||||
}
|
||||
|
||||
Log struct {
|
||||
ID string `json:"id" db:"id"`
|
||||
Type string `json:"type" db:"type"`
|
||||
Content string `json:"content" db:"content"`
|
||||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
TYPE_ACCOUNT = "account"
|
||||
)
|
||||
|
||||
func (self *Logger) Info(logType string, format string, args ...any) {
|
||||
fmt.Printf(fmt.Sprintf("[%s] INFO: %s", logType, format), args...)
|
||||
// TODO: push logs to DB
|
||||
}
|
||||
|
||||
func (self *Logger) Warn(logType string, format string, args ...any) {
|
||||
fmt.Fprintf(os.Stderr, fmt.Sprintf("[%s] WARN: %s", logType, format), args...)
|
||||
// TODO: push logs to DB
|
||||
}
|
||||
|
||||
func (self *Logger) Fatal(logType string, format string, args ...any) {
|
||||
fmt.Fprintf(os.Stderr, fmt.Sprintf("[%s] FATAL: %s", logType, format), args...)
|
||||
// we won't need to push fatal logs to DB, as these usually precede a panic or crash
|
||||
}
|
||||
|
||||
func (self *Logger) Fetch(id string) *Log {
|
||||
// TODO: log fetch
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *Logger) Search(typeFilters []string, content string, offset int, limit int) []Log {
|
||||
// TODO: log search
|
||||
return []Log{}
|
||||
}
|
||||
|
||||
func (self *Logger) Delete(id string) error {
|
||||
// TODO: log deletion
|
||||
// consider: logging the deletion of logs?
|
||||
// or just not deleting logs at all
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue