Skip to content

Commit

Permalink
s/logger/LOGGER/g; rename to clear that it's global
Browse files Browse the repository at this point in the history
  • Loading branch information
ssato committed Mar 14, 2015
1 parent 50123ec commit fe16bf4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
24 changes: 12 additions & 12 deletions anyconfig/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
container = anyconfig.mergeabledict.MergeableDict
# pylint: enable=C0103

logger = logging.getLogger(__name__)
LOGGER = logging.getLogger(__name__)


def set_loglevel(level):
"""
:param level: Log level, e.g. logging.INFO and logging.WARN.
"""
logger.setLevel(level)
LOGGER.setLevel(level)


def find_loader(config_path, forced_type=None):
Expand All @@ -48,15 +48,15 @@ def find_loader(config_path, forced_type=None):
if forced_type is not None:
cparser = anyconfig.backend.backends.find_by_type(forced_type)
if not cparser:
logger.error("No parser found for given type: %s", forced_type)
LOGGER.error("No parser found for given type: %s", forced_type)
return None
else:
cparser = anyconfig.backend.backends.find_by_file(config_path)
if not cparser:
logger.error("No parser found for given file: %s", config_path)
LOGGER.error("No parser found for given file: %s", config_path)
return None

logger.debug("Using config parser of type: %s", cparser.type())
LOGGER.debug("Using config parser of type: %s", cparser.type())
return cparser


Expand Down Expand Up @@ -84,15 +84,15 @@ def single_load(config_path, forced_type=None, ignore_missing=False,
if cparser is None:
return None

logger.info("Loading: %s", config_path)
LOGGER.info("Loading: %s", config_path)
if template:
try:
logger.debug("Compiling: %s", config_path)
LOGGER.debug("Compiling: %s", config_path)
config_content = anyconfig.template.render(config_path, context)
return cparser.loads(config_content, ignore_missing=ignore_missing,
**kwargs)
except:
logger.warn("Failed to compile %s, fallback to no template "
LOGGER.warn("Failed to compile %s, fallback to no template "
"mode", config_path)

return cparser.load(config_path, ignore_missing=ignore_missing,
Expand Down Expand Up @@ -201,11 +201,11 @@ def loads(config_content, forced_type=None, template=True, context={},

if template:
try:
logger.debug("Compiling")
LOGGER.debug("Compiling")
config_content = anyconfig.template.render_s(config_content,
context)
except:
logger.warn("Failed to compile and fallback to no template "
LOGGER.warn("Failed to compile and fallback to no template "
"mode: '%s'", config_content[:50] + '...')

return cparser.loads(config_content, **kwargs)
Expand All @@ -222,7 +222,7 @@ def _find_dumper(config_path, forced_type=None):
cparser = find_loader(config_path, forced_type)

if cparser is None or not getattr(cparser, "dump", False):
logger.warn("Dump method not implemented. Fallback to "
LOGGER.warn("Dump method not implemented. Fallback to "
"JsonConfigParser")
cparser = anyconfig.backend.json_.JsonConfigParser()

Expand All @@ -242,7 +242,7 @@ def dump(data, config_path, forced_type=None, **kwargs):
"""
dumper = _find_dumper(config_path, forced_type)

logger.info("Dumping: %s", config_path)
LOGGER.info("Dumping: %s", config_path)
dumper.dump(data, config_path, **kwargs)


Expand Down
6 changes: 3 additions & 3 deletions anyconfig/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import anyconfig.mergeabledict
import anyconfig.utils

SUPPORTED = False

logger = logging.getLogger(__name__)
SUPPORTED = False
LOGGER = logging.getLogger(__name__)


def mk_opt_args(keys, kwargs):
Expand Down Expand Up @@ -43,7 +43,7 @@ def mk_dump_dir_if_not_exist(f):
dumpdir = os.path.dirname(f)

if not os.path.exists(dumpdir):
logger.debug("Creating output dir as it's not found: %s", dumpdir)
LOGGER.debug("Creating output dir as it's not found: %s", dumpdir)
os.makedirs(dumpdir)


Expand Down
5 changes: 2 additions & 3 deletions anyconfig/backend/ini_.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

from anyconfig.compat import configparser, iteritems

logger = logging.getLogger(__name__)

LOGGER = logging.getLogger(__name__)
SUPPORTED = True # It should be available w/ python dist always.

_SEP = ','


Expand Down Expand Up @@ -82,7 +81,7 @@ def _load_impl(config_fp, sep=_SEP, **kwargs):
config[s][k] = _parse(v, sep)

except Exception:
logger.warn(sys.exc_info()[-1])
LOGGER.warn(sys.exc_info()[-1])
raise

return config
Expand Down
8 changes: 3 additions & 5 deletions anyconfig/backend/xml_.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
# License: MIT
#
# pylint: disable=R0921

import logging

import anyconfig.backend.base as Base
import anyconfig.compat

logger = logging.getLogger(__name__)

LOGGER = logging.getLogger(__name__)
SUPPORTED = True

try:
# First, try lxml which is compatible with elementtree and looks faster a
# lot. See also: http://getpython3.com/diveintopython3/xml.html
Expand All @@ -24,7 +22,7 @@
try:
import elementtree.ElementTree as etree
except ImportError:
logger.warn("ElementTree module is not available. Disabled "
LOGGER.warn("ElementTree module is not available. Disabled "
"XML support.")
SUPPORTED = False

Expand All @@ -45,7 +43,7 @@ def etree_getroot_fromsrc(src):
return etree.parse(src).getroot()
else:
def _dummy_fun(*args, **kwargs):
logger.warn("Return None as XML module is not available: "
LOGGER.warn("Return None as XML module is not available: "
"args=%s, kwargs=%s", ','.join(args), str(kwargs))
return None

Expand Down
8 changes: 4 additions & 4 deletions anyconfig/backend/yaml_.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import logging
import anyconfig.backend.base as Base

logger = logging.getLogger(__name__)

LOGGER = logging.getLogger(__name__)
SUPPORTED = False
try:
import yaml
SUPPORTED = True
except ImportError:
logger.warn("YAML module is not available. Disabled its support.")
LOGGER.warn("YAML module is not available. Disabled its support.")


if SUPPORTED:
Expand All @@ -34,12 +34,12 @@ def yaml_dump(data, fp, **kwargs):
return yaml.dump(data, fp, **kwargs)
else:
def yaml_load(*args, **kwargs):
logger.warn("Return {} as YAML module is not available: "
LOGGER.warn("Return {} as YAML module is not available: "
"args=%s, kwargs=%s", ','.join(args), str(kwargs))
return {}

def yaml_dump(*args, **kwargs):
logger.warn("Do nothing as YAML module is not available: "
LOGGER.warn("Do nothing as YAML module is not available: "
"args=%s, kwargs=%s", ','.join(args), str(kwargs))
pass

Expand Down
5 changes: 2 additions & 3 deletions anyconfig/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

from anyconfig.compat import raw_input, copen

logger = logging.getLogger(__name__)

LOGGER = logging.getLogger(__name__)
TEMPLATE_SUPPORT = False
try:
import jinja2
Expand All @@ -22,7 +21,7 @@ def tmpl_env(paths):
return jinja2.Environment(loader=jinja2.FileSystemLoader(paths))

except ImportError:
logger.warn("Jinja2 is not available on your system, so "
LOGGER.warn("Jinja2 is not available on your system, so "
"template support will be disabled.")

class TemplateNotFound(RuntimeError):
Expand Down

0 comments on commit fe16bf4

Please sign in to comment.