Skip to content

Commit

Permalink
pymzn: move debug into log module and fix imports in __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
paolodragone committed Feb 6, 2019
1 parent ad311e8 commit df5aca6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
27 changes: 2 additions & 25 deletions pymzn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,14 @@
problems encoded in MiniZinc and parse the solutions into Python objects."""

import ast
import logging

from .log import *
from . import config
from . import dzn
from .dzn import *
from . import mzn
from .mzn import *
from .mzn import templates

__version__ = '0.17.1'
__all__ = ['debug', 'config']
__all__.extend(dzn.__all__)
__all__.extend(mzn.__all__)

# TODO: update python2 branch

_debug_handler = None
_pymzn_logger = logging.getLogger(__name__)
_pymzn_logger.addHandler(logging.NullHandler())

def debug(dbg=True):
"""Enables or disables debugging messages on the standard output."""
global _debug_handler
if dbg and _debug_handler is None:
_debug_handler = logging.StreamHandler()
_pymzn_logger.addHandler(_debug_handler)
_pymzn_logger.setLevel(logging.DEBUG)
elif not dbg and _debug_handler is not None:
_pymzn_logger.removeHandler(_debug_handler)
_debug_handler = None
_pymzn_logger.setLevel(logging.WARNING)
__all__ = ['config'] + log.__all__ + dzn.__all__ + mzn.__all__


def main():
Expand Down
18 changes: 18 additions & 0 deletions pymzn/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,22 @@

import logging

__all__ = ['debug']

logger = logging.getLogger(__package__)

_debug_handler = None
logger.addHandler(logging.NullHandler())

def debug(dbg=True):
"""Enables or disables debugging messages on the standard output."""
global _debug_handler
if dbg and _debug_handler is None:
_debug_handler = logging.StreamHandler()
logger.addHandler(_debug_handler)
logger.setLevel(logging.DEBUG)
elif not dbg and _debug_handler is not None:
logger.removeHandler(_debug_handler)
_debug_handler = None
logger.setLevel(logging.WARNING)

0 comments on commit df5aca6

Please sign in to comment.