Skip to content

Commit bd98505

Browse files
authored
Read log entries from jsonPayload and protoPayload. (firebase#3539)
Today, function logs with structured data (e.g. those generated using firebase-functions SDK's logger api) do not show up in `firebase functions:log` command: ```js // index.js exports.hello = functions.https.onRequest((request, response) => { info("Hello logs!", {structuredData: true}); info("hello world!"); response.send("Hello from Firebase!"); }); ``` ```bash $ firebase functions:log 2021-06-30T12:47:42.955491814Z D hello: Function execution started 2021-06-30T12:47:43.050Z I hello: # LOOK HERE: where's the message? 2021-06-30T12:47:43.050Z I hello: hello world! 2021-06-30T12:47:43.061418239Z D hello: Function execution took 107 ms, finished with status code: 200 ``` This happens because structured log entries are stored in [`jsonPayload` field](https://cloud.google.com/logging/docs/structured-logging), not `textPayload` field. In addition to correctly parsing `jsonPayload` field, we will also correctly parse log entries with `protoPayload` fields (in most cases, these log entries come from audit logs). *After* ```bash 2021-06-30T12:47:42.955491814Z D hello: Function execution started 2021-06-30T12:47:43.050Z I hello: {"message":"Hello logs!","structuredData":true} 2021-06-30T12:47:43.050Z I hello: hello world! 2021-06-30T12:47:43.061418239Z D hello: Function execution took 107 ms, finished with status code: 200 ```
1 parent 8680f9b commit bd98505

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
- Firestore Emulator UI now supports deleting documents and collections recursively.
66
- Fixes some Storage Emulator UI errors.
77
- Fixes some issues when using Emulator UI on a different device.
8+
- Fixes issues where functions:log command did not showing some log entries. (#3539)

src/commands/functions-log.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ module.exports = new Command("functions:log")
4848
entry.timestamp,
4949
_.get(entry, "severity", "?").substring(0, 1),
5050
_.get(entry, "resource.labels.function_name") + ":",
51-
_.get(entry, "textPayload", "")
51+
entry.textPayload ||
52+
JSON.stringify(entry.jsonPayload) ||
53+
JSON.stringify(entry.protoPayload) ||
54+
""
5255
);
5356
}
5457
if (_.isEmpty(entries)) {

0 commit comments

Comments
 (0)