def test_log_setup_file_handler_configured(): setup_logging() logger = logging.getLogger() file_handler = [ h for h in logger.handlers if isinstance(h, logging.FileHandler) ] assert file_handler is not None
def test_log_setup_socket_handler_configured(): setup_logging() logger = logging.getLogger() socket_handler = [ h for h in logger.handlers if isinstance(h, logging.handlers.SocketHandler) ] assert socket_handler is not None
import logging from log import log import submodule # this is a standard method for creating a logging object LOG = logging.getLogger(__name__) if __name__ == '__main__': # we set up the logging configuration # additionally, the logging.yaml has a console handler, so all logs will be emitted to # stdout as well as the filehanlders specified log.setup_logging('../log/config/logging.yaml', log_dir='./logs') # a logging message from the main thread (take note of the first item, should be main.py) LOG.info('This is a test log for the main thread') # a logging message from the imported thread (the first item should be submodule.py) submodule.write_info_log('This is an imported INFO log message.') # we can also disable imported logs by name submodule_logger = logging.getLogger('submodule') # before setting the submodule_logger level, we can that because our global logger # is set at INFO, the following won't emit submodule.write_debug_log("This won't write anywhere.") # but if we set the level of that logger to debug, it will now emit submodule_logger.setLevel(logging.DEBUG) submodule.write_debug_log('Now this will write out')
__author__ = 'Thiago Balbo' __email__ = '*****@*****.**' __version__ = '0.1.0' import dotenv from log import log # load environment variables dotenv.load_dotenv('.env') # config file load must come before getting logger log.setup_logging(default_path='log/config.yml')
def test_log_setup_level_debug(): setup_logging() logger = logging.getLogger() assert logger.level == logging.DEBUG