Code Monkey home page Code Monkey logo

Comments (6)

jaclar avatar jaclar commented on July 22, 2024 2

Seems like the logger feature was merged after the last release (0.1.2): #121
So I hope it is part of the next release.

Anyway, strange that it is already mentioned in the official documentation.

from firebase-functions-python.

matthewnaples avatar matthewnaples commented on July 22, 2024

I'm also having this problem. The following code is broken, but when removing the logger import and logger.info(...) call, the code works and successfully deploys

from firebase_functions import https_fn, logger

from firebase_admin import initialize_app, firestore

initialize_app()


@https_fn.on_request()
def write_data(req: https_fn.Request) -> https_fn.Response:
    """This function will take the request and write its data to cloud firestore in a collection called 'submissions'"""
    #log that the function has been called
    logger.info("write_data function called")

    # Get the data from the request
    data = req.get_json()

    # Get the firestore client
    firestore_client = firestore.client()

    # Write the data to the firestore
    firestore_client.collection("submissions").add(data)

    # Return a response
    return https_fn.Response("OK", 200)

from firebase-functions-python.

MWals avatar MWals commented on July 22, 2024

Too bad that the logger can not be imported in version 0.12, looking forward to the next release.

Meanwhile, this is my workaround to get logs inside the emulator:

import logging

logger = logging.getLogger('cloudfunctions.googleapis.com%2Fcloud-functions')
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())


@https_fn.on_request()
def text_fxn(req: https_fn.Request) -> https_fn.Response:
logger.log(msg='Log from function"', level=logging.INFO)
    return https_fn.Response("OK", status=200)

Output:

i  functions: Beginning execution of "us-central1-on_packing_box_closed"
>  Log from function
i  functions: Finished "us-central1-on_packing_box_closed" in 1.831333ms

from firebase-functions-python.

sandpat avatar sandpat commented on July 22, 2024

I think you can just copy paste the following file in your code for time being:

https://raw.githubusercontent.com/firebase/firebase-functions-python/3662d07c0f84cc19fdf5d548553fb9c7b5dd00d7/src/firebase_functions/logger.py

from firebase-functions-python.

TRON-N avatar TRON-N commented on July 22, 2024

I came here looking for a solution to this issue, but it seems to be fixed in 0.2.0 #167. Thanks Everyone!

from firebase-functions-python.

exaby73 avatar exaby73 commented on July 22, 2024

Since this issue is fixed in the latest version (sorry about that), I feel safe to close this issue. Thanks for your patience everyone :)

from firebase-functions-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.