rorodata / firefly

function as a service
http://rorodata.github.io/firefly
Apache License 2.0
194 stars 30 forks source link

Setup logger in firefly #57

Closed sohail535 closed 7 years ago

sohail535 commented 7 years ago

This is how I setup logger.


def firefly_function():
    pass

def firefly_function2():
    pass

def setup_logger():
   pass

setup_logger()

There should be a logger in firefly which user can use, instead of writing his own logger.

anandology commented 7 years ago

Good idea.

Firefly should setup logging with INFO level by default. It might be a good idea to specify the log level as command-line argument or env variable (separate issue).

The application should be able to create a logger and start using it without any configuration.

import logging

logger = logging.getLogger(__name__)

def square(x):
    logger.info("square(%s)", x)
    return x*x
palnabarun commented 7 years ago

I thought @sohail535 meant logging inside functions. For that, it can be built as a Firefly Plugin.

The implementation can be something like this:

import logging

class FireflyLogger:
    def __init__(self, name, log_level="INFO"):
        # setup the logger
    def __getattr__(self, attr):
        self._validate_attr(attr)
        def helper(log_text):
            # log (attr, log_text) using the logger
        return helper
     def _validate_attr(self, attr):
         # validate the user passed attr here
from firefly import FireflyLogger

logger = FireflyLogger(__name__, log_level = 'DEBUG')

def power(a, b):
    logger.info("power({}, {})".format(a, b))
    return a**b
anandology commented 7 years ago

The standard Python logging module already does it. We don't need to ask people to learn about firefly logger.