<commit_before>'''
Created on 15.10.2013

@author: marscher
'''
__all__ = ['getLogger', 'enabled']

import logging
from emma2.util.config import configParser as config, AttribStore

enabled = False

""" set up a dummy logger if logging is disabled"""
class dummyLogger:
    def dummy(self, kwargs):
        pass
    def __getattr__(self, name):
        return self.dummy

def setupLogging():
    """
        parses emma2 configuration file and creates a logger config from that 
    """
    section = 'Logging'
    args = AttribStore()
    args.enabled = config.getboolean(section, 'enabled')
    args.toconsole = config.getboolean(section, 'toconsole')
    args.tofile = config.getboolean(section, 'tofile')
    args.file = config.get(section, 'file')
    args.level = config.get(section, 'level')
    args.format = config.get(section, 'format')
    
    if args.enabled:
        if args.tofile and args.file:
            filename = args.file
        else:
            filename = None
    
        logging.basicConfig(level=args.level,
                    format=args.format,
                    datefmt='%d-%m-%y %H:%M:%S',
                    filename=filename,
                    filemode='a')
        
        """ in case we want to log to both file and stream, add a separate handler"""
        if args.toconsole and args.tofile:
            ch = logging.StreamHandler()
            ch.setLevel(args.level)
            ch.setFormatter(logging.Formatter(args.format))
            logging.getLogger('').addHandler(ch)
    
    global enabled   
    enabled = args.enabled

def getLogger(name = None):
    if not enabled:
        return dummyLogger()
    """ if name is not given, return a logger with name of the calling module."""
    if not name:
        import traceback
        t = traceback.extract_stack(limit=2)
        path = t[0][0]
        pos = path.rfind('emma2')
        name = path[pos:]
    return logging.getLogger(name)


# init logging
setupLogging()<commit_msg>[log] do not return a new dummy instance per getLogger call<commit_after>'''
Created on 15.10.2013

@author: marscher
'''
__all__ = ['getLogger', 'enabled']

import logging
from emma2.util.config import configParser as config, AttribStore

enabled = False

""" set up a dummy logger if logging is disabled"""
class dummyLogger:
    def dummy(self, kwargs):
        pass
    def __getattr__(self, name):
        return self.dummy
    
dummyInstance = None

def setupLogging():
    """
        parses emma2 configuration file and creates a logger config from that 
    """
    global enabled, dummyInstance
    
    section = 'Logging'
    args = AttribStore()
    args.enabled = config.getboolean(section, 'enabled')
    args.toconsole = config.getboolean(section, 'toconsole')
    args.tofile = config.getboolean(section, 'tofile')
    args.file = config.get(section, 'file')
    args.level = config.get(section, 'level')
    args.format = config.get(section, 'format')
    
    if args.enabled:
        if args.tofile and args.file:
            filename = args.file
        else:
            filename = None
    
        logging.basicConfig(level=args.level,
                    format=args.format,
                    datefmt='%d-%m-%y %H:%M:%S',
                    filename=filename,
                    filemode='a')
        
        """ in case we want to log to both file and stream, add a separate handler"""
        if args.toconsole and args.tofile:
            ch = logging.StreamHandler()
            ch.setLevel(args.level)
            ch.setFormatter(logging.Formatter(args.format))
            logging.getLogger('').addHandler(ch)
    else:
        dummyInstance = dummyLogger()
    
    enabled = args.enabled

def getLogger(name = None):
    if not enabled:
        return dummyInstance
    """ if name is not given, return a logger with name of the calling module."""
    if not name:
        import traceback
        t = traceback.extract_stack(limit=2)
        path = t[0][0]
        pos = path.rfind('emma2')
        name = path[pos:]
    return logging.getLogger(name)


# init logging
setupLogging()
{'fraction_non_alphanumeric': 0.10762113464816167, 'fraction_numerical': 0.006817628439250061, 'mean_word_length': 2.3075684380032206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6768174', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1164, 'n_words': 335}