feat(logging): add database logging support and refactor logging system
- Implement new database logging functionality with separate logs database - Refactor PostLog function to store logs in database while maintaining console output - Add new InitLogsDatabase function and related database operations - Update main.go to support separate database paths for data and logs - Add logging for user creation events
This commit is contained in:
+18
-4
@@ -6,12 +6,18 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"super-frpc/postLog"
|
||||
"time"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
var db *sql.DB
|
||||
var logsDB *sql.DB
|
||||
|
||||
func GetLogsDatabase() *sql.DB {
|
||||
return logsDB
|
||||
}
|
||||
|
||||
type User struct {
|
||||
UserID int
|
||||
@@ -35,15 +41,23 @@ type FrpcInstance struct {
|
||||
CreatedBy string
|
||||
}
|
||||
|
||||
func InitDatabase(dbPath string) error {
|
||||
InitUserDatabase(dbPath)
|
||||
InitFrpcDatabase(dbPath)
|
||||
func InitDatabase(dbPath_data string, dbPath_log string) error {
|
||||
InitUserDatabase(dbPath_data)
|
||||
InitFrpcDatabase(dbPath_data)
|
||||
postLog.InitLogsDatabase(dbPath_log)
|
||||
return nil
|
||||
}
|
||||
|
||||
func CloseDatabase() error {
|
||||
if db != nil {
|
||||
return db.Close()
|
||||
if err := db.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if logsDB != nil {
|
||||
if err := logsDB.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user