NozeIO / MicroExpress

A micro web server framework on top of Swift NIO
http://www.alwaysrightinstitute.com/microexpress-nio2/
126 stars 14 forks source link

Adding a way to capture logs #11

Closed nathanfallet closed 4 years ago

nathanfallet commented 4 years ago

This is a tiny change, but it allows to capture the logs to do something else with it than just print it.

By default, the function logger prints the logs (like previously, no changes)

But it can be personalized:

let app = Express()

app.logger = { log in
    // Do something else with the log line
}

For example, in an iOS app, we can capture this log and append it into a UITextView:

app.logger = { log in
    textView.text.append("\(log)\n")
}

So I think this is a useful change (I will personally use it, but other people might find it useful)

helje5 commented 4 years ago

Thanks for the patch, but I don't really want to complicate MicroExpress. Sorry! For more functionality, please checkout Macro. It's like MicroExpress, but with the intention to be more full featured (like Noze.io).

In fact it does feature better logging, including the JS like console.log and friends. Build on top of the official Server Side Swift Logging framework: Console.swift.