Set logging preferences via command line flags. Closes #20
This commit is contained in:
parent
1133edf716
commit
259923b303
@ -95,7 +95,7 @@ func (s *server) onConnection(ws *websocket.Conn) {
|
||||
func (s *server) Listen() {
|
||||
http.Handle(s.pattern, websocket.Handler(s.onConnection))
|
||||
|
||||
log.Printf("Starting the websocket listener on: %s", s.pattern)
|
||||
log.Tracef("Starting the websocket listener on: %s", s.pattern)
|
||||
|
||||
for {
|
||||
select {
|
||||
@ -121,7 +121,7 @@ func (s *server) Listen() {
|
||||
fmt.Println("PING?", ping)
|
||||
|
||||
case err := <-s.errCh:
|
||||
log.Println("Error:", err.Error())
|
||||
log.Error("Error:", err.Error())
|
||||
|
||||
case <-s.doneCh:
|
||||
return
|
||||
|
@ -24,17 +24,17 @@ func Start() error {
|
||||
resetDirectories()
|
||||
|
||||
if err := setupStats(); err != nil {
|
||||
log.Println("failed to setup the stats")
|
||||
log.Error("failed to setup the stats")
|
||||
return err
|
||||
}
|
||||
|
||||
if err := setupStorage(); err != nil {
|
||||
log.Println("failed to setup the storage")
|
||||
log.Error("failed to setup the storage")
|
||||
return err
|
||||
}
|
||||
|
||||
if err := createInitialOfflineState(); err != nil {
|
||||
log.Println("failed to create the initial offline state")
|
||||
log.Error("failed to create the initial offline state")
|
||||
return err
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ func createInitialOfflineState() error {
|
||||
}
|
||||
|
||||
func resetDirectories() {
|
||||
log.Println("Resetting file directories to a clean slate.")
|
||||
log.Trace("Resetting file directories to a clean slate.")
|
||||
|
||||
// Wipe the public, web-accessible hls data directory
|
||||
os.RemoveAll(config.Config.PublicHLSPath)
|
||||
|
@ -29,7 +29,7 @@ func StartThumbnailGenerator(chunkPath string, variantIndex int) {
|
||||
}
|
||||
case <-quit:
|
||||
//TODO: evaluate if this is ever stopped
|
||||
log.Println("thumbnail generator has stopped")
|
||||
log.Debug("thumbnail generator has stopped")
|
||||
ticker.Stop()
|
||||
return
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func (v *VideoSize) getString() string {
|
||||
func (t *Transcoder) Start() {
|
||||
command := t.getString()
|
||||
|
||||
log.Printf("Video transcoder started with %d stream variants.", len(t.variants))
|
||||
log.Tracef("Video transcoder started with %d stream variants.", len(t.variants))
|
||||
|
||||
_, err := exec.Command("sh", "-c", command).Output()
|
||||
if err != nil {
|
||||
|
@ -76,7 +76,7 @@ func StartVideoContentMonitor(storage models.ChunkStorageProvider) error {
|
||||
} else if filepath.Ext(event.Path) == ".ts" {
|
||||
segment, err := getSegmentFromPath(event.Path)
|
||||
if err != nil {
|
||||
log.Println("failed to get the segment from path")
|
||||
log.Error("failed to get the segment from path")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ func (h *Handler) OnCreateStream(timestamp uint32, cmd *rtmpmsg.NetConnectionCre
|
||||
//OnPublish handles the "OnPublish" of the rtmp service
|
||||
func (h *Handler) OnPublish(timestamp uint32, cmd *rtmpmsg.NetStreamPublish) error {
|
||||
// log.Printf("OnPublish: %#v", cmd)
|
||||
log.Println("Incoming stream connected.")
|
||||
log.Trace("Incoming stream connected.")
|
||||
|
||||
if cmd.PublishingName != config.Config.VideoSettings.StreamingKey {
|
||||
return errors.New("invalid streaming key; rejecting incoming stream")
|
||||
|
@ -45,7 +45,7 @@ func Start() {
|
||||
},
|
||||
})
|
||||
|
||||
log.Printf("RTMP server is listening for incoming stream on port: %d", port)
|
||||
log.Infof("RTMP server is listening for incoming stream on port: %d", port)
|
||||
if err := srv.Serve(listener); err != nil {
|
||||
log.Panicf("Failed to serve the rtmp service: %+v", err)
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func SetClientActive(clientID string) {
|
||||
|
||||
//RemoveClient removes a client from the active clients record
|
||||
func RemoveClient(clientID string) {
|
||||
log.Println("Removing the client:", clientID)
|
||||
log.Trace("Removing the client:", clientID)
|
||||
|
||||
delete(_stats.Clients, clientID)
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ type IPFSStorage struct {
|
||||
|
||||
//Setup sets up the ipfs storage for saving the video to ipfs
|
||||
func (s *IPFSStorage) Setup() error {
|
||||
log.Println("Setting up IPFS for external storage of video. Please wait..")
|
||||
log.Trace("Setting up IPFS for external storage of video. Please wait..")
|
||||
|
||||
s.gateway = ownconfig.Config.IPFS.Gateway
|
||||
|
||||
@ -267,9 +267,9 @@ func (s *IPFSStorage) createIPFSInstance() (*icore.CoreAPI, *core.IpfsNode, erro
|
||||
}
|
||||
|
||||
func (s *IPFSStorage) startIPFSNode() { //} icore.CoreAPI {
|
||||
defer log.Println("IPFS node exited")
|
||||
defer log.Debug("IPFS node exited")
|
||||
|
||||
log.Println("IPFS node is running")
|
||||
log.Trace("IPFS node is running")
|
||||
|
||||
bootstrapNodes := []string{
|
||||
// IPFS Bootstrapper nodes.
|
||||
|
@ -30,7 +30,7 @@ type S3Storage struct {
|
||||
|
||||
//Setup sets up the s3 storage for saving the video to s3
|
||||
func (s *S3Storage) Setup() error {
|
||||
log.Println("Setting up S3 for external storage of video...")
|
||||
log.Trace("Setting up S3 for external storage of video...")
|
||||
|
||||
s.s3Endpoint = config.Config.S3.Endpoint
|
||||
s.s3Region = config.Config.S3.Region
|
||||
@ -62,9 +62,9 @@ func (s *S3Storage) Save(filePath string, retryCount int) (string, error) {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Errorln("error uploading:", err.Error())
|
||||
log.Trace("error uploading:", err.Error())
|
||||
if retryCount < 4 {
|
||||
log.Println("Retrying...")
|
||||
log.Trace("Retrying...")
|
||||
return s.Save(filePath, retryCount+1)
|
||||
}
|
||||
}
|
||||
|
22
main.go
22
main.go
@ -23,10 +23,13 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Println(getVersion())
|
||||
configureLogging()
|
||||
|
||||
log.Infoln(getVersion())
|
||||
|
||||
configFile := flag.String("configFile", "config.yaml", "Config File full path. Defaults to current folder")
|
||||
enableDebugOptions := flag.Bool("enableDebugFeatures", false, "Enable additional debugging options.")
|
||||
enableVerboseLogging := flag.Bool("enableVerboseLogging", false, "Enable additional logging.")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
@ -34,23 +37,36 @@ func main() {
|
||||
logrus.SetReportCaller(true)
|
||||
}
|
||||
|
||||
if *enableVerboseLogging {
|
||||
log.SetLevel(log.TraceLevel)
|
||||
} else {
|
||||
log.SetLevel(log.InfoLevel)
|
||||
}
|
||||
|
||||
if err := config.Load(*configFile, getVersion()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// starts the core
|
||||
if err := core.Start(); err != nil {
|
||||
log.Println("failed to start the core package")
|
||||
log.Error("failed to start the core package")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := router.Start(); err != nil {
|
||||
log.Println("failed to start/run the router")
|
||||
log.Error("failed to start/run the router")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//getVersion gets the version string
|
||||
func getVersion() string {
|
||||
return fmt.Sprintf("Owncast v%s-%s (%s)", BuildVersion, BuildType, GitCommit)
|
||||
}
|
||||
|
||||
func configureLogging() {
|
||||
log.SetFormatter(&log.TextFormatter{
|
||||
FullTimestamp: true,
|
||||
})
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func Start() error {
|
||||
|
||||
port := config.Config.WebServerPort
|
||||
|
||||
log.Printf("Starting public web server on port: %d", port)
|
||||
log.Infof("Web server running on port: %d", port)
|
||||
|
||||
return http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user