Last active
February 27, 2019 10:47
-
-
Save suvayu/d6a8cf77a3c0857fe15e9fb1c5cb4733 to your computer and use it in GitHub Desktop.
Logging to a package's logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import dask | |
logger = logging.getLogger(__name__) | |
@dask.delayed | |
def times(arg, mult): | |
logger.info(f"Multiplying: {arg} * {mult}") | |
return arg * mult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from dask.distributed import LocalCluster, Client | |
from myfuncs import times | |
if __name__ == "__main__": | |
logger = logging.getLogger("myfuncs") | |
handler = logging.StreamHandler() | |
fmt = "{levelname}:{asctime}:{name}:{lineno}: {message}" | |
formatter = logging.Formatter(fmt, style="{") | |
handler.setFormatter(formatter) | |
logger.addHandler(handler) | |
# set the level only _after_ you have instantiated the logger | |
# doing it earlier will is simply ignored | |
logger.setLevel(logging.INFO) | |
logger.info("Starting") | |
cluster = LocalCluster(n_workers=2) | |
client = Client(cluster) | |
dld_times = times(6, 7) | |
logger.info(f"Result: {dld_times.compute()}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment