Closed sohail535 closed 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
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
The standard Python logging module already does it. We don't need to ask people to learn about firefly logger.
This is how I setup logger.
There should be a logger in firefly which user can use, instead of writing his own logger.