View logs of firebase functions in real time

The logs are viewable in the Firebase console (Functions -> Logs), but they are very hard to review with details hidden on accordion expansions.

Using the CLI you can specify the numbers of lines to return with the "-n" parameter:

firebase functions:log -n 100

You can also simulate real time logs by continually getting the logs and printing out the new entries.

https://github.com/fireRun-io/firebase-logging

const cmd = require("node-cmd");
const argv = require("yargs").argv;

let last = [];
const project = argv.project ? `--project ${argv.project}` : "";
const lines = argv.lines ? argv.lines : 100;

if (argv.h) {
  console.log(
    "Format: node firebase-logging.js --project=[projectId] --n=[number of lines]"
  );
  return;
}

const getLogs = () => {
  cmd.get(
    `firebase ${project} functions:log -n ${lines}`,
    (err, data, stderr) => {
      if (err) {
        console.error(err);
      }

      const splitData = data.trim().split("\n");
      const diff = splitData.filter((x) => !last.includes(x));

      if (diff.length > 0) {
        console.log(diff.join("\n"));
      }

      last = [...splitData];
    }
  );
};

getLogs();
setInterval(() => {
  getLogs();
}, 2000);


You can also see logs of deployed functions in console/cmd:

Using the Firebase CLI
To view logs with the firebase tool, use the functions:log command:

firebase functions:log

To view logs for a specific function, provide the function name as an argument:

firebase functions:log --only <FUNCTION_NAME>

For the full range of log viewing options, view the help for functions:log:

firebase help functions:log

https://firebase.google.com/docs/functions/writing-and-viewing-logs#viewing_logs


For those of us that prefer a CLI version

npx firebase-logging --project=YOUR_PROJECT --freq=1500

This will fetch logs from Firebase, refreshed every 1.5s. Thanks for Geoffery and his answer, for inspiration.


You can see logs in real time using the Firebase console. Choose your project, click the Functions product on the left, then click the Logs tab.