# Path: performanceplatform/collector/logging_setup.py
# def set_up_logging(
#         app_name,
#         log_level,
#         logfile_path,
#         logfile_name,
#         json_fields=None):
# 
#     if logfile_name is None:
#         logfile_name = 'production'
#     sys.excepthook = uncaught_exception_handler
#     logger = logging.getLogger()
#     logger.setLevel(log_level)
#     logger.addHandler(get_log_file_handler(
#         os.path.join(logfile_path, '{}.log'.format(logfile_name))))
#     logger.addHandler(get_json_log_handler(
#         os.path.join(logfile_path, '{}.json.log'.format(logfile_name)),
#         app_name,
#         json_fields=json_fields if json_fields else {}))
#     logger.info("{0} logging started".format(app_name))
# 
# def extra_fields_from_exception(exception):
#     """Exception into a dict to be passed to logger
# 
#     Standardise the way we send exception messages so they can be filtered in
#     kibana, also make it easy to add extra information in future.
#     """
#     return {
#         'exception_class': type(exception).__name__,
#         'exception_message': exception.message
#     }


from hamcrest import assert_that, has_entries
from performanceplatform.collector.logging_setup import (
    set_up_logging,
    extra_fields_from_exception)
import os
import logging
import json
import unittest


class TestJsonLogging(unittest.TestCase):

    def setUp(self):
        self.logger = logging.getLogger()

    def test_json_log_written_when_logger_called(self):

        set_up_logging('collector_foo', logging.DEBUG, './log', None)

# Path: performanceplatform/collector/logging_setup.py
# def set_up_logging(
#         app_name,
#         log_level,
#         logfile_path,
#         logfile_name,
#         json_fields=None):
# 
#     if logfile_name is None:
#         logfile_name = 'production'
#     sys.excepthook = uncaught_exception_handler
#     logger = logging.getLogger()
#     logger.setLevel(log_level)
#     logger.addHandler(get_log_file_handler(
#         os.path.join(logfile_path, '{}.log'.format(logfile_name))))
#     logger.addHandler(get_json_log_handler(
#         os.path.join(logfile_path, '{}.json.log'.format(logfile_name)),
#         app_name,
#         json_fields=json_fields if json_fields else {}))
#     logger.info("{0} logging started".format(app_name))
# 
# def extra_fields_from_exception(exception):
#     """Exception into a dict to be passed to logger
# 
#     Standardise the way we send exception messages so they can be filtered in
#     kibana, also make it easy to add extra information in future.
#     """
#     return {
#         'exception_class': type(exception).__name__,
#         'exception_message': exception.message
#     }


# Path: tests/performanceplatform/collector/test_logging_setup.py
from hamcrest import assert_that, has_entries
from performanceplatform.collector.logging_setup import (
    set_up_logging,
    extra_fields_from_exception)
import os
import logging
import json
import unittest



class TestJsonLogging(unittest.TestCase):

    def setUp(self):
        self.logger = logging.getLogger()

    def test_json_log_written_when_logger_called(self):

        set_up_logging('collector_foo', logging.DEBUG, './log', None)

        logging.info('Writing out JSON formatted logs m8')