Skip to content

Commit

Permalink
Added global logger
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Nov 4, 2020
1 parent 1ac7a60 commit fd82a7c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions astits/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions data_psi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package astits

import (
"fmt"
"log"

"github.com/asticode/go-astikit"
)
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package astits

import (
"fmt"
"log"
"time"

"github.com/asticode/go-astikit"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}

Expand Down
10 changes: 10 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
@@ -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) }

0 comments on commit fd82a7c

Please sign in to comment.