Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

67 lines
1.1 KiB

package conf
import (
"encoding/json"
"fmt"
"github.com/bluenviron/mediamtx/internal/logger"
)
// LogLevel is the logLevel parameter.
type LogLevel logger.Level
// MarshalJSON implements json.Marshaler.
func (d LogLevel) MarshalJSON() ([]byte, error) {
var out string
switch d {
case LogLevel(logger.Error):
out = "error"
case LogLevel(logger.Warn):
out = "warn"
case LogLevel(logger.Info):
out = "info"
case LogLevel(logger.Debug):
out = "debug"
default:
return nil, fmt.Errorf("invalid log level: %v", d)
}
return json.Marshal(out)
}
// UnmarshalJSON implements json.Unmarshaler.
func (d *LogLevel) UnmarshalJSON(b []byte) error {
var in string
if err := json.Unmarshal(b, &in); err != nil {
return err
}
switch in {
case "error":
*d = LogLevel(logger.Error)
case "warn":
*d = LogLevel(logger.Warn)
case "info":
*d = LogLevel(logger.Info)
case "debug":
*d = LogLevel(logger.Debug)
default:
return fmt.Errorf("invalid log level: '%s'", in)
}
return nil
}
// UnmarshalEnv implements envUnmarshaler.
func (d *LogLevel) UnmarshalEnv(s string) error {
return d.UnmarshalJSON([]byte(`"` + s + `"`))
}