zserge / lorca

Build cross-platform modern desktop apps in Go + HTML5
MIT License
8.04k stars 535 forks source link

[feature request] Specify where JS console log output goes? #86

Closed quillaja closed 4 years ago

quillaja commented 4 years ago

I couldn't find any documentation saying that this already exists, but it would be useful. Would it be possible in a near-future version to be able to specify an io.Writer to which the javascript console log output is written to? Now it goes to stdout or stderr. I'd like to be able to specify a file or null device (to disable console logging) in my application as it pollutes the console.

I could possibly put together a PR to implement such feature. It looks like the main culprit is lines 272-273 in chrome.go where the read loop gets a console call or exception and logs it using the standard logger.

if res.ID == 0 && res.Method == "Runtime.consoleAPICalled" || res.Method == "Runtime.exceptionThrown" {
    log.Println(params.Message)

I suppose the way to do this would be to accept an io.Writer somewhere when lorca is setup, create a custom logger with that writer, and then log with that instead of the standard logger.

quillaja commented 4 years ago

Though perhaps not a perfect solution, I realized I could just set the standard logger package output.