mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 08:45:38 +02:00
## Description We are attempting to hookup maitred to the API Maitred duties will be: - [ ] Hookup to the API - [ ] Wait for signal (from the API) to start Steam - [ ] Stop signal to stop the gaming session, clean up Steam... and maybe do the backup ## Summary by CodeRabbit - **New Features** - Introduced Docker-based deployment configurations for both the main and relay applications. - Added new API endpoints enabling real-time machine messaging and enhanced IoT operations. - Expanded database schema and actor types to support improved machine tracking. - **Improvements** - Enhanced real-time communication and relay management with streamlined room handling. - Upgraded dependencies, logging, and error handling for greater stability and performance. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: DatCaptainHorse <DatCaptainHorse@users.noreply.github.com> Co-authored-by: Kristian Ollikainen <14197772+DatCaptainHorse@users.noreply.github.com>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package common
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
type CustomHandler struct {
|
|
Handler slog.Handler
|
|
}
|
|
|
|
func (h *CustomHandler) Enabled(_ context.Context, level slog.Level) bool {
|
|
return h.Handler.Enabled(nil, level)
|
|
}
|
|
|
|
func (h *CustomHandler) Handle(_ context.Context, r slog.Record) error {
|
|
// Format the timestamp as "2006/01/02 15:04:05"
|
|
timestamp := r.Time.Format("2006/01/02 15:04:05")
|
|
// Convert level to uppercase string (e.g., "INFO")
|
|
level := strings.ToUpper(r.Level.String())
|
|
// Build the message
|
|
msg := fmt.Sprintf("%s %s %s", timestamp, level, r.Message)
|
|
|
|
// Handle additional attributes if they exist
|
|
var attrs []string
|
|
r.Attrs(func(a slog.Attr) bool {
|
|
attrs = append(attrs, fmt.Sprintf("%s=%v", a.Key, a.Value))
|
|
return true
|
|
})
|
|
if len(attrs) > 0 {
|
|
msg += " " + strings.Join(attrs, " ")
|
|
}
|
|
|
|
// Write the formatted message to stdout
|
|
_, err := fmt.Fprintln(os.Stdout, msg)
|
|
return err
|
|
}
|
|
|
|
func (h *CustomHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
|
return &CustomHandler{Handler: h.Handler.WithAttrs(attrs)}
|
|
}
|
|
|
|
func (h *CustomHandler) WithGroup(name string) slog.Handler {
|
|
return &CustomHandler{Handler: h.Handler.WithGroup(name)}
|
|
}
|