From fd82a7c82b019126ea57e46c7f918ff2bf4111a5 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 4 Nov 2020 12:37:20 +0100 Subject: [PATCH] Added global logger --- astits/main.go | 3 +++ data_psi.go | 3 +-- descriptor.go | 5 ++--- logger.go | 10 ++++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 logger.go diff --git a/astits/main.go b/astits/main.go index 07cd7eb..680542b 100644 --- a/astits/main.go +++ b/astits/main.go @@ -40,6 +40,9 @@ func main() { cmd := astikit.FlagCmd() flag.Parse() + // Set logger + astits.SetLogger(log.New(log.Writer(), log.Prefix(), log.Flags())) + // Handle signals handleSignals() diff --git a/data_psi.go b/data_psi.go index 64a13b3..2423a32 100644 --- a/data_psi.go +++ b/data_psi.go @@ -2,7 +2,6 @@ package astits import ( "fmt" - "log" "github.com/asticode/go-astikit" ) @@ -293,7 +292,7 @@ func psiTableType(tableID int) string { case tableID == 0x73: return PSITableTypeTOT default: - log.Printf("astits: unlisted PSI table ID %d\n", tableID) + logger.Debugf("astits: unlisted PSI table ID %d\n", tableID) } return PSITableTypeUnknown } diff --git a/descriptor.go b/descriptor.go index 222bb39..704f07d 100644 --- a/descriptor.go +++ b/descriptor.go @@ -2,7 +2,6 @@ package astits import ( "fmt" - "log" "time" "github.com/asticode/go-astikit" @@ -634,7 +633,7 @@ func newDescriptorExtension(i *astikit.BytesIterator, offsetEnd int) (d *Descrip return } default: - log.Printf("astits: unlisted extension tag 0x%x\n", d.Tag) + logger.Debugf("astits: unlisted extension tag 0x%x\n", d.Tag) } return } @@ -1395,7 +1394,7 @@ func parseDescriptors(i *astikit.BytesIterator) (o []*Descriptor, err error) { return } default: - log.Printf("astits: unlisted descriptor tag 0x%x\n", d.Tag) + logger.Debugf("astits: unlisted descriptor tag 0x%x\n", d.Tag) } } diff --git a/logger.go b/logger.go new file mode 100644 index 0000000..9596d63 --- /dev/null +++ b/logger.go @@ -0,0 +1,10 @@ +package astits + +import "github.com/asticode/go-astikit" + +// Right now we use a global logger because it feels weird to inject a logger in pure functions +// Indeed, logger is only needed to let the developer know when an unhandled descriptor or id has been found +// in the stream +var logger = astikit.AdaptStdLogger(nil) + +func SetLogger(l astikit.StdLogger) { logger = astikit.AdaptStdLogger(l) }