-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (49 loc) · 1.45 KB
/
main.go
File metadata and controls
62 lines (49 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"flag"
"net/http"
"time"
"github.com/taigrr/log-socket/v2/browser"
logger "github.com/taigrr/log-socket/v2/log"
"github.com/taigrr/log-socket/v2/ws"
)
const readHeaderTimeout = 5 * time.Second
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 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)
}
}
func newMux() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("/ws", ws.LogSocketHandler)
mux.HandleFunc("/api/namespaces", ws.NamespacesHandler)
mux.HandleFunc("/", browser.LogSocketViewHandler)
return mux
}
func newServer(address string) *http.Server {
return &http.Server{
Addr: address,
Handler: newMux(),
ReadHeaderTimeout: readHeaderTimeout,
}
}
func main() {
defer logger.Flush()
flag.Parse()
go generateLogs()
logger.Fatal(newServer(*addr).ListenAndServe())
}