Skip to content

Commit

Permalink
trying to avoid daisy_logs artifact after running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pattonw committed Sep 12, 2024
1 parent a008f2a commit 65fe3a1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions daisy/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .block import BlockStatus
from .context import Context
from .logging import set_log_basedir
from .messages import (
AcquireBlock,
BlockFailed,
Expand Down Expand Up @@ -56,6 +57,7 @@ def __init__(self, context=None):
self.context = Context.from_env()
logger.debug("Client context: %s", self.context)

set_log_basedir(self.context["logdir"])
self.host = self.context["hostname"]
self.port = int(self.context["port"])
self.worker_id = int(self.context["worker_id"])
Expand Down
3 changes: 2 additions & 1 deletion daisy/context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import logging
import os
from .logging import get_log_basedir

logger = logging.getLogger(__name__)

Expand All @@ -11,7 +12,7 @@ class Context:

def __init__(self, **kwargs):

self.__dict = dict(**kwargs)
self.__dict = dict(logdir=get_log_basedir(), **kwargs)

def copy(self):

Expand Down
8 changes: 7 additions & 1 deletion daisy/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ def set_log_basedir(path):
else:
LOG_BASEDIR = None

def get_log_basedir():
"""Get the base directory for logging."""
global LOG_BASEDIR
return LOG_BASEDIR


def get_worker_log_basename(worker_id, task_id=None):
"""Get the basename of log files for individual workers."""

global LOG_BASEDIR

if LOG_BASEDIR is None:
return None

Expand Down
1 change: 1 addition & 0 deletions daisy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .block import BlockStatus
from .block_bookkeeper import BlockBookkeeper
from .context import Context
from .logging import get_log_basedir
from .messages import (
AcquireBlock,
BlockFailed,
Expand Down
1 change: 1 addition & 0 deletions daisy/task_worker_pools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .context import Context
from .logging import get_log_basedir
from .server_observer import ServerObserver
from .worker_pool import WorkerPool
import logging
Expand Down
8 changes: 8 additions & 0 deletions tests/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

from daisy.logging import set_log_basedir, get_log_basedir


@pytest.fixture(autouse=True)
def logdir(tmp_path):
set_log_basedir(tmp_path / "daisy_logs")

0 comments on commit 65fe3a1

Please sign in to comment.