def test_task_log(tmpdir, execution, task_func, run_count, fail_count, success_count, inact_count, get_handler):
    """Test the task logging thoroughly including the common
    logging schemes, execution (main, thread, process) and
    outcomes (fail, success, inaction).

    This task may take some time but should cover most of the
    issues with logging.
    """

    # Set session (and logging)
    session = Session(config={"debug": True, "silence_task_logging": False, "execution": "process"})
    rocketry.session = session
    session.set_as_default()

    task_logger = logging.getLogger(session.config.task_logger_basename)
    task_logger.handlers = [
        get_handler()
    ]

    task = FuncTask(task_func, name="mytask", start_cond=AlwaysTrue(), execution=execution, session=session)

    session.config.shut_cond = (TaskStarted(task="mytask") >= run_count) | ~SchedulerStarted(period=TimeDelta("10 second"))
    session.start()

    assert (TaskStarted(task="mytask") >= run_count).observe(session=session)

    # Test history
    history = list(task.logger.get_records())
    logger = task.logger
    assert run_count == logger.filter_by(action="run").count()
    assert success_count == logger.filter_by(action="success").count()
    assert fail_count == logger.filter_by(action="fail").count()
    assert inact_count == logger.filter_by(action="inaction").count()

    # Test relevant log items
    for record in history:
        is_tasl_log = isinstance(record, TaskLogRecord)
        if not isinstance(record, dict):
            record = record.dict()
        assert record["task_name"] == "mytask"
        assert isinstance(record["created"], float)
        assert isinstance(record["start"], datetime.datetime if is_tasl_log else float)
        if record["action"] != "run":
            assert isinstance(record["end"], datetime.datetime if is_tasl_log else float)
            assert isinstance(record["runtime"], datetime.timedelta if is_tasl_log else float)

        # Test traceback
        if record["action"] == "fail":
            assert re.match(
                r'Traceback \(most recent call last\):\n  File ".+", line [0-9]+, in [\s\S]+, in run_failing\n    raise RuntimeError\("Task failed"\)\nRuntimeError: Task failed',
                record["exc_text"]
            )

    # Test some other relevant APIs
    assert history == list(task.logger.get_records())
    assert history[-1] == task.logger.get_latest()
    assert history == list(session.get_task_log())

    assert run_count == len(list(task.logger.get_records(action="run")))
    assert success_count == len(list(task.logger.get_records(action="success")))
    assert fail_count == len(list(task.logger.get_records(action="fail")))
    assert inact_count == len(list(task.logger.get_records(action="inaction")))
Test the task logging thoroughly including the common
logging schemes, execution (main, thread, process) and
outcomes (fail, success, inaction).

This task may take some time but should cover most of the
issues with logging.
rocketry/test/schedule/test_core.py