$app.logger() could be used to writes any logs into the database so that they can be later explored from the PocketBase Admin UI > Logs section.

For better performance and to minimize blocking on hot paths, note that logs are written with debounce and on batches:

  • 3 seconds after the last debounced log write
  • when the batch threshold is reached (currently 200)
  • right before app termination to attempt saving everything from the existing logs queue

    All standard slog.Logger methods are available but below is a list with some of the most notable ones. Note that attributes are represented as key-value pair arguments.

    $app.logger().debug("Debug message!") $app.logger().debug( "Debug message with attributes!", "name", "John Doe", "id", 123, )
    $app.logger().info("Info message!") $app.logger().info( "Info message with attributes!", "name", "John Doe", "id", 123, )
    $app.logger().warn("Warning message!") $app.logger().warn( "Warning message with attributes!", "name", "John Doe", "id", 123, )
    $app.logger().error("Error message!") $app.logger().error( "Error message with attributes!", "id", 123, "error", err, )

    with(atrs...) creates a new local logger that will "inject" the specified attributes with each following log.

    const l = $app.logger().with("total", 123) // results in log with data {"total": 123} l.info("message A") // results in log with data {"total": 123, "name": "john"} l.info("message B", "name", "john")

    withGroup(name) creates a new local logger that wraps all logs attributes under the specified group name.

    const l = $app.logger().withGroup("sub") // results in log with data {"sub": { "total": 123 }} l.info("message A", "total", 123)

    You can control various log settings like logs retention period, minimal log level, request IP logging, etc. from the logs settings panel:

    Logs settings screenshot