mirror of
https://github.com/teacat/chaturbate-dvr.git
synced 2025-10-29 16:59:59 +00:00
Channel_file.go - fix issue with segments not correctly ending when they were supposed to Log_type.go - moved log type to it's own file, setup global logging (touches on issue #47) Main.go - added update_log_level handler, setting global log level Channel.go, channel_internal.go, channel_util.go - updated to use new log_type Manager.go - updated to use new log_type, update from .com to .global (issue #74) Channel_update.go, create_channel.go, delete_channel.go, get_channel.go, get_settings.go, listen_update.go, pause_channel.go, resume_channel.go, terminal_program.go - go fmt / go vet Chaturbate_channels.json.sample - added sample json of the channels file, for mapping in docker config List_channels.go - refactored to sort by online status, so online is always at the first ones you see Script.js - adjust default settings, added pagination, added global log logic Index.html - updated to use online version of tocas ui, added pagination, added global log logic, visual improvements Removal of local tocas folder since using online version
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package chaturbate
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
type LogType string
|
|
|
|
type LogLevelRequest struct {
|
|
LogLevel LogType `json:"log_level" binding:"required"`
|
|
}
|
|
|
|
// Define the log types
|
|
const (
|
|
LogTypeDebug LogType = "DEBUG"
|
|
LogTypeInfo LogType = "INFO"
|
|
LogTypeWarning LogType = "WARN"
|
|
LogTypeError LogType = "ERROR"
|
|
)
|
|
|
|
// Global log level with mutex protection
|
|
var (
|
|
globalLogLevel LogType
|
|
logMutex sync.RWMutex // Protects global log level access
|
|
)
|
|
|
|
// UnmarshalJSON ensures that LogType is properly parsed from JSON.
|
|
func (l *LogType) UnmarshalJSON(b []byte) error {
|
|
var s string
|
|
if err := json.Unmarshal(b, &s); err != nil {
|
|
return err
|
|
}
|
|
|
|
parsed := LogType(strings.ToUpper(s))
|
|
switch parsed {
|
|
case LogTypeDebug, LogTypeInfo, LogTypeWarning, LogTypeError:
|
|
*l = parsed
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("invalid log level: %s", s)
|
|
}
|
|
}
|
|
|
|
// InitGlobalLogLevel initializes the global log level from settings.
|
|
func InitGlobalLogLevel(initialLevel LogType) {
|
|
SetGlobalLogLevel(initialLevel)
|
|
}
|
|
|
|
// SetGlobalLogLevel updates the global log level
|
|
func SetGlobalLogLevel(level LogType) {
|
|
logMutex.Lock()
|
|
defer logMutex.Unlock()
|
|
globalLogLevel = level
|
|
}
|
|
|
|
// GetGlobalLogLevel retrieves the current global log level
|
|
func GetGlobalLogLevel() LogType {
|
|
logMutex.RLock()
|
|
defer logMutex.RUnlock()
|
|
return globalLogLevel
|
|
}
|