Skip to content

message is empty when using jsonPayload with functions.logger #1404

Closed
@nilsreichardt

Description

@nilsreichardt

Related issues

[REQUIRED] Version info

node: 16

firebase-functions: 4.4.0

firebase-tools: 11.24.1

firebase-admin: 10.3.0

[REQUIRED] Test case

exports.loggingtest = functions.https.onRequest((req, res) => {
  functions.logger.info({
    message: "we are healthy",
    userId: "123",
  });
  res.status(200).send("OK");
});

[REQUIRED] Steps to reproduce

  1. Use code from "Test case"
  2. Call the function
  3. Open Cloud Logging Explorer

[REQUIRED] Expected behavior

[REQUIRED] Actual behavior

message is an empty string.

image

Were you able to successfully deploy your functions?

Yes

Additional

When using @google-cloud/logging, everything works:

// Imports the Google Cloud client library
import { Logging } from "@google-cloud/logging";

async function quickstart(
  projectId = "PROJECT_ID", // Your Google Cloud Platform project ID
  logName = "my-log" // The name of the log to write to
) {
  // Creates a client
  const logging = new Logging({ projectId });

  // Selects the log to write to
  const log = logging.log(logName);

  // The metadata associated with the entry
  const metadata = {
    resource: { type: "global" },
    // See: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity
    severity: "INFO",
  };

  const json = {
    message: "Hello, world!",
    userId: "123",
  };

  // Prepares a log entry
  const entry = log.entry(metadata, json);

  async function writeLog() {
    // Writes the log entry
    await log.write(entry);
    console.log(`Logged: ${JSON.stringify(json)}`);
  }

  // eslint-disable-next-line @typescript-eslint/no-floating-promises
  writeLog();
}


// eslint-disable-next-line @typescript-eslint/no-floating-promises
quickstart();

image

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