mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 20:28:15 +03:00
Save owncast logs to log file. Closes #908
This commit is contained in:
parent
bf6a3d9e85
commit
381daaec9b
8 changed files with 79 additions and 26 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -30,6 +30,7 @@ hls/
|
||||||
dist/
|
dist/
|
||||||
data/
|
data/
|
||||||
transcoder.log
|
transcoder.log
|
||||||
|
owncast.log*
|
||||||
chat.db
|
chat.db
|
||||||
.yp.key
|
.yp.key
|
||||||
backup/
|
backup/
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,7 +41,3 @@ func GetReleaseString() string {
|
||||||
|
|
||||||
return fmt.Sprintf("Owncast v%s-%s (%s)", versionNumber, buildPlatform, gitCommit)
|
return fmt.Sprintf("Owncast v%s-%s (%s)", versionNumber, buildPlatform, gitCommit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTranscoderLogFilePath() string {
|
|
||||||
return filepath.Join(LogDirectory, "transcoder.log")
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/owncast/owncast/config"
|
"github.com/owncast/owncast/config"
|
||||||
"github.com/owncast/owncast/core/data"
|
"github.com/owncast/owncast/core/data"
|
||||||
|
"github.com/owncast/owncast/logging"
|
||||||
"github.com/owncast/owncast/models"
|
"github.com/owncast/owncast/models"
|
||||||
"github.com/owncast/owncast/utils"
|
"github.com/owncast/owncast/utils"
|
||||||
)
|
)
|
||||||
|
@ -101,7 +102,7 @@ func (t *Transcoder) Start() {
|
||||||
|
|
||||||
err = _commandExec.Start()
|
err = _commandExec.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("Transcoder error. See ", config.GetTranscoderLogFilePath(), " for full output to debug.")
|
log.Errorln("Transcoder error. See ", logging.GetTranscoderLogFilePath(), " for full output to debug.")
|
||||||
log.Panicln(err, command)
|
log.Panicln(err, command)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ func (t *Transcoder) Start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("transcoding error. look at ", config.GetTranscoderLogFilePath(), " to help debug. your copy of ffmpeg may not support your selected codec of", t.codec.Name(), "https://owncast.online/docs/troubleshooting/#codecs")
|
log.Errorln("transcoding error. look at ", logging.GetTranscoderLogFilePath(), " to help debug. your copy of ffmpeg may not support your selected codec of", t.codec.Name(), "https://owncast.online/docs/troubleshooting/#codecs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +143,7 @@ func (t *Transcoder) getString() string {
|
||||||
hlsOptionsString = "-hls_flags " + strings.Join(hlsOptionFlags, "+")
|
hlsOptionsString = "-hls_flags " + strings.Join(hlsOptionFlags, "+")
|
||||||
}
|
}
|
||||||
ffmpegFlags := []string{
|
ffmpegFlags := []string{
|
||||||
fmt.Sprintf(`FFREPORT=file="%s":level=32`, config.GetTranscoderLogFilePath()),
|
fmt.Sprintf(`FFREPORT=file="%s":level=32`, logging.GetTranscoderLogFilePath()),
|
||||||
t.ffmpegPath,
|
t.ffmpegPath,
|
||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
"-loglevel warning",
|
"-loglevel warning",
|
||||||
|
|
3
go.mod
3
go.mod
|
@ -8,6 +8,8 @@ require (
|
||||||
github.com/aws/aws-sdk-go v1.38.44
|
github.com/aws/aws-sdk-go v1.38.44
|
||||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||||
github.com/grafov/m3u8 v0.11.1
|
github.com/grafov/m3u8 v0.11.1
|
||||||
|
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
|
||||||
|
github.com/lestrrat-go/strftime v1.0.4 // indirect
|
||||||
github.com/markbates/pkger v0.17.1
|
github.com/markbates/pkger v0.17.1
|
||||||
github.com/mattn/go-sqlite3 v1.14.7
|
github.com/mattn/go-sqlite3 v1.14.7
|
||||||
github.com/microcosm-cc/bluemonday v1.0.9
|
github.com/microcosm-cc/bluemonday v1.0.9
|
||||||
|
@ -16,6 +18,7 @@ require (
|
||||||
github.com/nareix/joy5 v0.0.0-20200712071056-a55089207c88
|
github.com/nareix/joy5 v0.0.0-20200712071056-a55089207c88
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||||
github.com/oschwald/geoip2-golang v1.5.0
|
github.com/oschwald/geoip2-golang v1.5.0
|
||||||
|
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 // indirect
|
||||||
github.com/schollz/sqlite3dump v1.2.4
|
github.com/schollz/sqlite3dump v1.2.4
|
||||||
github.com/shirou/gopsutil v3.21.4+incompatible
|
github.com/shirou/gopsutil v3.21.4+incompatible
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/sirupsen/logrus v1.8.1
|
||||||
|
|
10
go.sum
10
go.sum
|
@ -25,6 +25,11 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
|
||||||
|
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4=
|
||||||
|
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
|
||||||
|
github.com/lestrrat-go/strftime v1.0.4 h1:T1Rb9EPkAhgxKqbcMIPguPq8glqXTA1koF8n9BHElA8=
|
||||||
|
github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
|
||||||
github.com/markbates/pkger v0.17.1 h1:/MKEtWqtc0mZvu9OinB9UzVN9iYCwLWuyUv4Bw+PCno=
|
github.com/markbates/pkger v0.17.1 h1:/MKEtWqtc0mZvu9OinB9UzVN9iYCwLWuyUv4Bw+PCno=
|
||||||
github.com/markbates/pkger v0.17.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
|
github.com/markbates/pkger v0.17.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
|
||||||
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||||
|
@ -44,9 +49,13 @@ github.com/oschwald/geoip2-golang v1.5.0 h1:igg2yQIrrcRccB1ytFXqBfOHCjXWIoMv85lV
|
||||||
github.com/oschwald/geoip2-golang v1.5.0/go.mod h1:xdvYt5xQzB8ORWFqPnqMwZpCpgNagttWdoZLlJQzg7s=
|
github.com/oschwald/geoip2-golang v1.5.0/go.mod h1:xdvYt5xQzB8ORWFqPnqMwZpCpgNagttWdoZLlJQzg7s=
|
||||||
github.com/oschwald/maxminddb-golang v1.8.0 h1:Uh/DSnGoxsyp/KYbY1AuP0tYEwfs0sCph9p/UMXK/Hk=
|
github.com/oschwald/maxminddb-golang v1.8.0 h1:Uh/DSnGoxsyp/KYbY1AuP0tYEwfs0sCph9p/UMXK/Hk=
|
||||||
github.com/oschwald/maxminddb-golang v1.8.0/go.mod h1:RXZtst0N6+FY/3qCNmZMBApR19cdQj43/NM9VkrNAis=
|
github.com/oschwald/maxminddb-golang v1.8.0/go.mod h1:RXZtst0N6+FY/3qCNmZMBApR19cdQj43/NM9VkrNAis=
|
||||||
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo=
|
||||||
|
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM=
|
||||||
github.com/schollz/sqlite3dump v1.2.4 h1:b3dgcKLsHZhF6OsB2EK+e/oA77vh4P/45TAh2R35OFI=
|
github.com/schollz/sqlite3dump v1.2.4 h1:b3dgcKLsHZhF6OsB2EK+e/oA77vh4P/45TAh2R35OFI=
|
||||||
github.com/schollz/sqlite3dump v1.2.4/go.mod h1:SEajZA5udi52Taht5xQYlFfHwr7AIrqPrLDrAoFv17o=
|
github.com/schollz/sqlite3dump v1.2.4/go.mod h1:SEajZA5udi52Taht5xQYlFfHwr7AIrqPrLDrAoFv17o=
|
||||||
github.com/shirou/gopsutil v3.21.4+incompatible h1:fuHcTm5mX+wzo542cmYcV9RTGQLbnHLI5SyQ5ryTVck=
|
github.com/shirou/gopsutil v3.21.4+incompatible h1:fuHcTm5mX+wzo542cmYcV9RTGQLbnHLI5SyQ5ryTVck=
|
||||||
|
@ -57,6 +66,7 @@ github.com/spf13/cobra v0.0.4-0.20190109003409-7547e83b2d85/go.mod h1:1l0Ry5zgKv
|
||||||
github.com/spf13/pflag v1.0.4-0.20181223182923-24fa6976df40/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
github.com/spf13/pflag v1.0.4-0.20181223182923-24fa6976df40/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
|
|
@ -7,7 +7,10 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||||
|
"github.com/rifflock/lfshook"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
logger "github.com/sirupsen/logrus"
|
logger "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
@ -21,14 +24,50 @@ type OCLogger struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var Logger *OCLogger
|
var Logger *OCLogger
|
||||||
|
var _level logrus.Level
|
||||||
|
|
||||||
// Setup configures our custom logging destinations.
|
// Setup configures our custom logging destinations.
|
||||||
func Setup() {
|
func Setup(enableDebugOptions bool, enableVerboseLogging bool) {
|
||||||
logger.SetOutput(os.Stdout) // Send all logs to console
|
// Write logs to a file
|
||||||
|
path := getLogFilePath()
|
||||||
|
writer, _ := rotatelogs.New(
|
||||||
|
path+".%Y%m%d%H%M",
|
||||||
|
rotatelogs.WithLinkName(path),
|
||||||
|
rotatelogs.WithMaxAge(time.Duration(86400)*time.Second),
|
||||||
|
rotatelogs.WithRotationTime(time.Duration(604800)*time.Second),
|
||||||
|
)
|
||||||
|
|
||||||
|
logMapping := lfshook.WriterMap{
|
||||||
|
logrus.InfoLevel: writer,
|
||||||
|
logrus.DebugLevel: writer,
|
||||||
|
logrus.TraceLevel: writer,
|
||||||
|
logrus.WarnLevel: writer,
|
||||||
|
logrus.ErrorLevel: writer,
|
||||||
|
logrus.FatalLevel: writer,
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.AddHook(lfshook.NewHook(
|
||||||
|
logMapping,
|
||||||
|
&logger.TextFormatter{},
|
||||||
|
))
|
||||||
|
|
||||||
|
if enableVerboseLogging {
|
||||||
|
logrus.SetLevel(logrus.TraceLevel)
|
||||||
|
} else {
|
||||||
|
logrus.SetLevel(logrus.InfoLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to stdout console
|
||||||
|
logger.SetOutput(os.Stdout)
|
||||||
|
|
||||||
|
// Write to our custom logging hook for the log API
|
||||||
_logger := new(OCLogger)
|
_logger := new(OCLogger)
|
||||||
logger.AddHook(_logger)
|
logger.AddHook(_logger)
|
||||||
|
|
||||||
|
if enableDebugOptions {
|
||||||
|
logrus.SetReportCaller(true)
|
||||||
|
}
|
||||||
|
|
||||||
Logger = _logger
|
Logger = _logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
logging/paths.go
Normal file
15
logging/paths.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package logging
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/owncast/owncast/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetTranscoderLogFilePath() string {
|
||||||
|
return filepath.Join(config.LogDirectory, "transcoder.log")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLogFilePath() string {
|
||||||
|
return filepath.Join(config.LogDirectory, "owncast.log")
|
||||||
|
}
|
21
main.go
21
main.go
|
@ -8,7 +8,6 @@ import (
|
||||||
|
|
||||||
"github.com/markbates/pkger"
|
"github.com/markbates/pkger"
|
||||||
"github.com/owncast/owncast/logging"
|
"github.com/owncast/owncast/logging"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/owncast/owncast/config"
|
"github.com/owncast/owncast/config"
|
||||||
|
@ -30,7 +29,6 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configureLogging()
|
|
||||||
|
|
||||||
// Enable bundling of admin assets
|
// Enable bundling of admin assets
|
||||||
_ = pkger.Include("/admin")
|
_ = pkger.Include("/admin")
|
||||||
|
@ -57,12 +55,14 @@ func main() {
|
||||||
if BuildPlatform != "" {
|
if BuildPlatform != "" {
|
||||||
config.BuildPlatform = BuildPlatform
|
config.BuildPlatform = BuildPlatform
|
||||||
}
|
}
|
||||||
log.Infoln(config.GetReleaseString())
|
|
||||||
|
|
||||||
if *logDirectory != "" {
|
if *logDirectory != "" {
|
||||||
config.LogDirectory = *logDirectory
|
config.LogDirectory = *logDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configureLogging(*enableDebugOptions, *enableVerboseLogging)
|
||||||
|
log.Infoln(config.GetReleaseString())
|
||||||
|
|
||||||
// Create the data directory if needed
|
// Create the data directory if needed
|
||||||
if !utils.DoesFileExists("data") {
|
if !utils.DoesFileExists("data") {
|
||||||
os.Mkdir("./data", 0700)
|
os.Mkdir("./data", 0700)
|
||||||
|
@ -83,16 +83,6 @@ func main() {
|
||||||
log.Exit(0)
|
log.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *enableDebugOptions {
|
|
||||||
logrus.SetReportCaller(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
if *enableVerboseLogging {
|
|
||||||
log.SetLevel(log.TraceLevel)
|
|
||||||
} else {
|
|
||||||
log.SetLevel(log.InfoLevel)
|
|
||||||
}
|
|
||||||
|
|
||||||
config.EnableDebugFeatures = *enableDebugOptions
|
config.EnableDebugFeatures = *enableDebugOptions
|
||||||
|
|
||||||
if *dbFile != "" {
|
if *dbFile != "" {
|
||||||
|
@ -144,11 +134,10 @@ func main() {
|
||||||
if err := router.Start(); err != nil {
|
if err := router.Start(); err != nil {
|
||||||
log.Fatalln("failed to start/run the router", err)
|
log.Fatalln("failed to start/run the router", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureLogging() {
|
func configureLogging(enableDebugFeatures bool, enableVerboseLogging bool) {
|
||||||
logging.Setup()
|
logging.Setup(enableDebugFeatures, enableVerboseLogging)
|
||||||
log.SetFormatter(&log.TextFormatter{
|
log.SetFormatter(&log.TextFormatter{
|
||||||
FullTimestamp: true,
|
FullTimestamp: true,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue