Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View logs of firebase functions in real time

I'm using the firebase functions and it's the first time I use node.

My question is very simple, or so I think.

I create a simple function, where, theoretically, if a new field is added to the database, this function must react.

my code is the following:

const functions = require('firebase-functions');


'use strict';


exports.newItem = functions.database.ref('/test')
  .onCreate((snapshot, context) => {


    snapshot = change.after;
    const val = snapshot.val();

    console.log('i´m alive');

    return null;
  })

;

I'm looking for where to see if the log that I have inside the "newItem" function is shown or not.

As I read, I use "firebase functions: log" from the console, but this returns previous logs, not real time.

I have also seen the use of: gcloud functions logs read, as I read here.

But this always returns: -bash: gcloud: command not found I have installed "gcloud functions", but I'm still lost.

I feel if the question is not very well explained, but in summary, I look for a console where to see the logs in real time, just like it does intelij or android studio with the tab logcat.

I would appreciate an explanation for beginners.

Thanks in advance and greetings.

like image 610
Sergio76 Avatar asked Sep 21 '18 15:09

Sergio76


Video Answer


3 Answers

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

like image 109
GorvGoyl Avatar answered Oct 20 '22 13:10

GorvGoyl


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.

like image 45
Doug Stevenson Avatar answered Oct 20 '22 12:10

Doug Stevenson


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.

like image 5
bjornl Avatar answered Oct 20 '22 13:10

bjornl