Streaming Firebase Function logs to a local terminal would be very helpful since the Firebase Console web interface for logs is pretty sluggish to work with.
Does any one know a way to achieve this?
Using the Firebase CLI, according to the documentation, run the command:
firebase functions:log
This gives you a dump of recent logs, but it doesn't "stream" them to your terminal. Unfortunately, this is the best you can do.
If you're a gcloud user, there are equivalent commands, as described in its documentation. There is also no option to stream the logs live with gcloud.
If you want a "live" view of logs of your deployed functions, you're going to have to use the Firebase or Google Cloud console.
If you're doing active development and need the logs for code you've just written, it might be easier to use the Firebase emulator suite to run functions locally, so you can see logs appear live in the terminal where the emulator is running.
Related
I have the firebase emulator running in a docker container locally for testing. The emulator includes everything I'm using for my app (firestore, auth, functions, storage) so that I can develop and test independently of the production environment.
However, I'm getting these warnings which are making me nervous:
functions: Beginning execution of "myFunction"
⚠ External network resource requested!
- URL: "http://---.---.---.---/computeMetadata/v1/instance"
- Be careful, this may be a production service.
I don't know what that URL is? Does it mean I've misconfigured something somewhere?
I'm also getting these warnings:
⚠ emulators: You are not currently authenticated so some features may not work correctly. Please run firebase login to authenticate the CLI.
⚠ functions: You are not signed in to the Firebase CLI. If you have authorized this machine using gcloud application-default credentials those may be discovered and used to access production services.
⚠ functions: Unable to fetch project Admin SDK configuration, Admin SDK behavior in Cloud Functions emulator may be incorrect.
But I don't think I want to authenticate, right? I don't want to touch anything to do with the live project on production while testing locally. Can I safely ignore these, or is there a good reason to authenticate?
The warnings are indicative that there had some issues while initialization during the setup for emulators .
Make sure that the emulator is installed by the following command: firebase setup:emulators:firestore, for this you can refer Documentation.
Deploy your function in the firebase in order to get recognized. you can refer to the Documentation using firebase deploy --only functions
Also to be sure please check your Firebase json and see if the local host is configured and not the production host,just to be sure.
For further reference you can follow up the stackoverflow thread Docker authentication issueand Firestore emulatorwhere a similar issue has been raised by other users which might be helpful.
When running a Firebase function, my logs are very noisy mostly because of those 2 messages
Be careful, this may be a production service.
⚠ External network resource requested!
I know I am running a production service, and yes I am requesting an external ressource 😅 can I disable them?
Thanks
Normally using --quiet would silence this message, however because there are so many emulators, the Firebase team couldn't reach a consensus on whether to allow this to be silenced when used with firebase emulators:start (see firebase-tools Issue #2859).
The official stance on this is to set the logs filter to only show "user" logs using the Emulator Suite UI's Logs Viewer and let the regular log feed log everything.
I am running firebase functions in local using command - firebase serve.
It is not confirming if it is serving, if so in which port, and not logging any call to functions. Earlier I used to get these info. NOw, just stuck in few steps (see pic)
But, it is actually serving as I checked from browser.
How do we get these missing information and log outputs?
It would be great to run the Database emulator in a console and then, for example, the functions emulator in another console. In this fashion, You could upload your test-data to the Realtime DB and test/debug your function many times without having to reload all the test-data.
I tried to run only the database in a console like this:
firebase emulators:start --only database
But when I do the same for functions, the emulator hub gets deployed on the next port, so the database and the functions won't communicate to each other, i.e. the triggers won't fire at delete/create/etc. events on the DB.
I tried to find a way to tell the emulator to use a particular running hub, but still no luck.
Any help would be much appreciated.
I've added/setup the firebase pubsub emulator that is running on my localhost on port 8085. Up till this point I had need to use the pubsub in Googel cloud, where I would use their console to create topics and could also review messages published to those topics.
Now that it's running locally, there doesn't seem to be a UI to manage topics/messages and I can't seem to find documentation that explains how to create a topic on the local pubsub, how to review existing topics and how to review messages?
In addition, if I am writing a cloud function that references the pubsub library, will it automatically use my local emulator version if it's running or do I need to specify the host/port in my node.js function someplace? Any examples of this out there?
I believe their is an http API I Can use to create topics,but again, I can't find any documentation on this or find references to see what topics exist and what messages have been sent to the topics.
Any help is appreciated.
In order to connect your app to the local emulator you must set some environment variables like explained here
About the UI of the emulator you can access it on http://localhost:4000 like this documentation page mentions, although I am not sure if there are management tools to manage topics or messages in there.