Skip to content

Cloud Function and trigger log messages are built even when the log level discards them #10887

Open

Description

@mtrezza

New Feature / Enhancement Checklist

Current Limitation

Parse Server builds the log message for every Cloud Function call and every trigger run before the logger decides whether to write it. The success logs default to info, so with logLevel set to error or warn each message is built and then discarded.

  • Cloud Functions: the success log serializes the parameters and the whole result with JSON.stringify (FunctionsRouter.js).
  • Triggers: logTriggerAfterHook and logTriggerSuccessBeforeHook serialize the object and the trigger result (triggers.js). Their callers convert the input before the call, for example with Utils.safeToJSON(parseObject) or, for afterFind, with JSON.stringify(resultsAsJSON), so that part runs even when the level is silent.

The logger knows which levels are disabled, because LoggerController replaces their methods with no-ops (LoggerController.js), but by then the caller has already built the message.

Measured on Parse Server 9.11.1-alpha.2 with logLevel: 'error' (Node.js 22, Apple M4 Pro), the Cloud Function success log cost about 0.01 ms per call for a 3 KB result, 0.07 ms for 17 KB and 0.14 ms for 93 KB, which was up to 2% of the server CPU time of those requests. The trigger logs were not measured. The code is unchanged on the current alpha branch.

Feature / Enhancement Description

Build these messages only when their level is enabled.

The logger already supports this: LoggerController.log calls any argument that is a function (LoggerController.js), and logRequest and logResponse pass their message as a function, so it is only built when verbose is enabled (LoggerController.js). The Cloud Function and trigger logs could pass their message the same way, with the conversions at the trigger call sites moved into that function.

Example Use Case

  1. Parse Server runs with logLevel: 'warn' to keep the log volume low in production.
  2. A client calls a Cloud Function that returns a large result, or saves an object of a class that has a beforeSave or afterSave trigger.
  3. Parse Server skips the serialization for the log line, because the line would not be written.

Alternatives / Workarounds

Set the corresponding logLevels options to silent:

logLevels: {
  cloudFunctionSuccess: 'silent',
  triggerAfter: 'silent',
  triggerBeforeSuccess: 'silent',
}

This skips the serialization inside the log functions, but not the conversions at the trigger call sites. It also has to be kept in sync with logLevel by hand: the lines stay off when logLevel is later raised to info.

3rd Party References

Other loggers defer expensive log arguments in a similar way, for example lambda suppliers in Log4j 2 and isLevelEnabled in pino.

Activity

  1. parse-github-assistant commented on Nov 15, 2026

    @parse-github-assistant

    🚀 Thanks for opening this issue! We are excited about your ideas for improvement!

  2. Mani7527 commented on Nov 24, 2026

    @Mani7527

    Hi! I'd like to work on this. I checked that it still applies on current alpha: the Cloud Function success log still runs JSON.stringify on the input and result in FunctionsRouter.js, and the trigger call sites still convert the object (Utils.safeToJSON, JSON.stringify(resultsAsJSON) for afterFind) before calling the log helpers.

    My plan:

    • Pass the Cloud Function success log message as a function, so LoggerController.log only builds it when the level is enabled, the same way logRequest / logResponse do
    • Do the same for logTriggerAfterHook and logTriggerSuccessBeforeHook, moving the conversions at their call sites into that function
    • Add tests that the message is not built when the level is disabled (e.g. logLevel: 'error'), and that the log output is unchanged when it is enabled

    I'll open a PR against alpha once the tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions