import logging
import logging.handlers
import os

class Logger(object):

  def __init__(self, name, default_loglevel='INFO', fmt=None, syslog=None):
    self.name   = name
    self.syslog = syslog
    self.fmt = fmt if fmt is not None else "%(asctime)-15s %(name)s %(levelname)s %(message)s"

    if 'LOGLEVEL' in os.environ:
      self.level = os.environ['LOGLEVEL'].upper()
    else:
      self.level = default_loglevel.upper()

    logging.basicConfig(format=self.fmt)
    self.logger = logging.getLogger(self.name)
    self.logger.setLevel(self.level)

    if self.syslog is not None and self.syslog not in (False, 0):
      if isinstance(self.syslog, (list, tuple)):
        _addr = tuple(self.syslog)
      elif isinstance(self.syslog, str):
        _addr = self.syslog
      else:
        _addr = "/dev/log" if os.path.exists("/dev/log") else None

      if _addr is not None:
        handler = logging.handlers.SysLogHandler(address=_addr)
        self.logger.addHandler(handler)


  def get(self):
    return self.logger

[((17, 4, 17, 40), 'logging.basicConfig', 'logging.basicConfig', (), '', False, 'import logging\n'), ((18, 18, 18, 46), 'logging.getLogger', 'logging.getLogger', ({(18, 36, 18, 45): 'self.name'}, {}), '(self.name)', False, 'import logging\n'), ((30, 18, 30, 63), 'logging.handlers.SysLogHandler', 'logging.handlers.SysLogHandler', (), '', False, 'import logging\n'), ((27, 30, 27, 56), 'os.path.exists', 'os.path.exists', ({(27, 45, 27, 55): '"""/dev/log"""'}, {}), "('/dev/log')", False, 'import os\n')]