Consider reusing the standard log
package or anything that is based on it.
That way the main library code and its consumers wouldn't have to depend on examples/jlog
.
It is completely possible to redirect default log
output to js like so:
type jsWriter struct {
js.Value
fname string
}
func (j jsWriter) Write(b []byte) (int, error) {
j.Value.Call(j.fname, string(b))
return len(b), nil
}
Then it is possible to use any logging package that is built on top of log
(or simply log.Println("This is a log that goes to the browser console")
.
Alternatively, it would be possible to simply export the abovementioned jsWriter
in such a way so that users of the mdc
wouldn't have to do it themselves. The following use case would be very simple:
func main() {
log.SetOutput(mdc.Console())
// use log as usual
}