Skip to content

Commit

Permalink
Fix logging on colab.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Jan 9, 2023
1 parent e92fb58 commit b8d00e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion law/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import six

from law.util import no_value, colored, ipykernel
from law.util import no_value, colored, ipykernel, ON_COLAB


_logging_setup = False
Expand All @@ -34,6 +34,10 @@ def setup_logging():
return
_logging_setup = True

# remove root handlers on colab
if ON_COLAB and logging.root.handlers:
logging.root.removeHandler(logging.root.handlers[0])

# setup the main law logger first and set its handler which is propagated to subloggers
logger = get_logger("law", skip_setup=True)
logger = setup_logger(logger, add_console_handler=False)
Expand Down
6 changes: 6 additions & 0 deletions law/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
except ImportError:
ipykernel = None

try:
import google.colab # noqa
ON_COLAB = True
except ImportError:
ON_COLAB = False


logger = logging.getLogger(__name__)

Expand Down

0 comments on commit b8d00e3

Please sign in to comment.