1
0
mirror of https://github.com/taigrr/log-socket synced 2026-03-20 21:52:21 -07:00

enable namespaced logging

This commit is contained in:
2025-11-10 16:07:28 -05:00
parent 9c571ca955
commit f86c2dbf46
11 changed files with 932 additions and 54 deletions

30
main.go
View File

@@ -5,20 +5,33 @@ import (
"net/http"
"time"
"github.com/taigrr/log-socket/browser"
logger "github.com/taigrr/log-socket/log"
"github.com/taigrr/log-socket/ws"
"github.com/taigrr/log-socket/v2/browser"
logger "github.com/taigrr/log-socket/v2/log"
"github.com/taigrr/log-socket/v2/ws"
)
var addr = flag.String("addr", "0.0.0.0:8080", "http service address")
func generateLogs() {
// Create loggers for different namespaces
apiLogger := logger.NewLogger("api")
dbLogger := logger.NewLogger("database")
authLogger := logger.NewLogger("auth")
for {
logger.Info("This is an info log!")
logger.Trace("This is a trace log!")
logger.Debug("This is a debug log!")
logger.Warn("This is a warn log!")
logger.Error("This is an error log!")
logger.Info("This is a default namespace log!")
apiLogger.Info("API request received")
apiLogger.Debug("Processing API call")
dbLogger.Info("Database query executed")
dbLogger.Warn("Slow query detected")
authLogger.Info("User authentication successful")
authLogger.Error("Failed login attempt detected")
logger.Trace("This is a trace log in default namespace!")
logger.Warn("This is a warning in default namespace!")
time.Sleep(2 * time.Second)
}
}
@@ -27,6 +40,7 @@ func main() {
defer logger.Flush()
flag.Parse()
http.HandleFunc("/ws", ws.LogSocketHandler)
http.HandleFunc("/api/namespaces", ws.NamespacesHandler)
http.HandleFunc("/", browser.LogSocketViewHandler)
go generateLogs()
logger.Fatal(http.ListenAndServe(*addr, nil))