macosloggingvapor

Vapor Logger doesn't log any messages into System Log


Environment:
Vapor 4.77
MacOS 13.5
Running on LocalHost:8080

Scenario:

  1. I've created a subclass within Vapor's app.logger to collect logs.
  2. Add set the logger base level to .info.
  3. I've added a log message.
  4. Don't see it in the system log; however I DO see it on the console (if I use the .info vs .debug modifier in the app.logger.

In the configure file:

var logger = Logger(label: "com.amourinetech.realtor")
  logger.logLevel = .info
  app.logger = logger

In the routes file:

func routes(_ app: Application) throws {

    app.get("hello") { req async -> String in
        app.logger.debug("Realtor says 'Hello Ric!")
        return "Hello, world!"
    }
    
    try app.register(collection: RealtorController())
}

I tried to elevate the message to '.debug' but it made no difference: enter image description here

Apparently, the console only shows INFO, not DEBUG information: enter image description here

I tried searching the system.log via the Console for 'info' or 'realtor', etc. but found nothing.

enter image description here


Solution

  • Vapor's ConsoleLogger (which is the default) for Vapor applications doesn't have any knowledge or interaction of OSLog which is what you need to make logs appear in the system log I believe.

    You can bootstrap a different logging backend that builds on SwiftLog easily. There are a couple of options that try and unify the two logging systems but it's not a clear match up so not everything works