Skip to content

Commit

Permalink
Log add_status calls (that aren't ActiveStatus)
Browse files Browse the repository at this point in the history
Log these at stacklevel=2 so we log the caller, not add_status
  • Loading branch information
benhoyt committed Jul 19, 2023
1 parent b920b3a commit 0967901
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ops/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Base objects for the Charm, events and metadata."""

import enum
import logging
import os
import pathlib
from typing import (
Expand Down Expand Up @@ -74,6 +75,9 @@
total=False)


logger = logging.getLogger(__name__)


class HookEvent(EventBase):
"""Events raised by Juju to progress a charm's lifecycle.
Expand Down Expand Up @@ -894,8 +898,12 @@ def add_status(self, status: model.StatusBase):
raise TypeError(f'status should be a StatusBase, not {type(status).__name__}')
model_ = self.framework.model
if self.handle.kind == 'collect_app_status':
if not isinstance(status, model.ActiveStatus):
logger.debug('Adding app status %s', status, stacklevel=2)
model_.app._collected_statuses.append(status)
else:
if not isinstance(status, model.ActiveStatus):
logger.debug('Adding unit status %s', status, stacklevel=2)
model_.unit._collected_statuses.append(status)


Expand Down

0 comments on commit 0967901

Please sign in to comment.