99b28c1d95
* refactor: start building an Android package Part of https://github.com/ooni/probe/issues/1335. This seems also a good moment to move some packages out of the engine, e.g., oonimkall. This package, for example, is a consumer of the engine, so it makes sense it's not _inside_ it. * fix: committed some stuff I didn't need to commit * fix: oonimkall needs to be public to build The side effect is that we will probably need to bump the major version number every time we change one of these APIs. (We can also of course choose to violate the basic guidelines of Go software, but I believe this is bad form.) I have no problem in bumping the major quite frequently and in any case this monorepo solution is convinving me more than continuing to keep a split between engine and cli. The need to embed assets to make the probe more reliable trumps the negative effects of having to ~frequently bump major because we expose a public API. * fix: let's not forget about libooniffi Honestly, I don't know what to do with this library. I added it to provide a drop in replacement for MK but I have no idea whether it's used and useful. I would not feel comfortable exposing it, unlike oonimkall, since we're not using it. It may be that the right thing to do here is just to delete the package and reduce the amount of code we're maintaining? * woops, we're still missing the publish android script * fix(publish-android.bash): add proper API key * ouch fix another place where the name changed
88 lines
1.6 KiB
Go
88 lines
1.6 KiB
Go
package tasks
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// ChanLogger is a logger targeting a channel
|
|
type ChanLogger struct {
|
|
emitter *EventEmitter
|
|
hasdebug bool
|
|
hasinfo bool
|
|
haswarning bool
|
|
out chan<- *Event
|
|
}
|
|
|
|
// Debug implements Logger.Debug
|
|
func (cl *ChanLogger) Debug(msg string) {
|
|
if cl.hasdebug {
|
|
cl.emitter.Emit("log", EventLog{
|
|
LogLevel: "DEBUG",
|
|
Message: msg,
|
|
})
|
|
}
|
|
}
|
|
|
|
// Debugf implements Logger.Debugf
|
|
func (cl *ChanLogger) Debugf(format string, v ...interface{}) {
|
|
if cl.hasdebug {
|
|
cl.Debug(fmt.Sprintf(format, v...))
|
|
}
|
|
}
|
|
|
|
// Info implements Logger.Info
|
|
func (cl *ChanLogger) Info(msg string) {
|
|
if cl.hasinfo {
|
|
cl.emitter.Emit("log", EventLog{
|
|
LogLevel: "INFO",
|
|
Message: msg,
|
|
})
|
|
}
|
|
}
|
|
|
|
// Infof implements Logger.Infof
|
|
func (cl *ChanLogger) Infof(format string, v ...interface{}) {
|
|
if cl.hasinfo {
|
|
cl.Info(fmt.Sprintf(format, v...))
|
|
}
|
|
}
|
|
|
|
// Warn implements Logger.Warn
|
|
func (cl *ChanLogger) Warn(msg string) {
|
|
if cl.haswarning {
|
|
cl.emitter.Emit("log", EventLog{
|
|
LogLevel: "WARNING",
|
|
Message: msg,
|
|
})
|
|
}
|
|
}
|
|
|
|
// Warnf implements Logger.Warnf
|
|
func (cl *ChanLogger) Warnf(format string, v ...interface{}) {
|
|
if cl.haswarning {
|
|
cl.Warn(fmt.Sprintf(format, v...))
|
|
}
|
|
}
|
|
|
|
// NewChanLogger creates a new ChanLogger instance.
|
|
func NewChanLogger(emitter *EventEmitter, logLevel string,
|
|
out chan<- *Event) *ChanLogger {
|
|
cl := &ChanLogger{
|
|
emitter: emitter,
|
|
out: out,
|
|
}
|
|
switch logLevel {
|
|
case "DEBUG", "DEBUG2":
|
|
cl.hasdebug = true
|
|
fallthrough
|
|
case "INFO":
|
|
cl.hasinfo = true
|
|
fallthrough
|
|
case "ERR", "WARNING":
|
|
fallthrough
|
|
default:
|
|
cl.haswarning = true
|
|
}
|
|
return cl
|
|
}
|