Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions snap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.1 - 4 November 2025

Update the type annotation of `log`'s `num_lines` parameter to indicate that `'all'` is accepted.

# 1.0.0.post0 - 14 October 2025

Update project URLs.
Expand Down
7 changes: 3 additions & 4 deletions snap/src/charmlibs/snap/_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,12 @@ def stop(self, services: list[str] | None = None, disable: bool = False) -> None
args = ['stop', '--disable'] if disable else ['stop']
self._snap_daemons(args, services)

def logs(self, services: list[str] | None = None, num_lines: int = 10) -> str:
def logs(self, services: list[str] | None = None, num_lines: int | Literal['all'] = 10) -> str:
"""Fetch a snap services' logs.

Args:
services (list): (optional) list of individual snap services to show logs from
(otherwise all)
num_lines (int): (optional) integer number of log lines to return. Default `10`
services: individual snap services to show logs from. Includes all by default.
num_lines: number of log lines to return, or 'all'. Returns 10 by default.
"""
args = ['logs', f'-n={num_lines}'] if num_lines else ['logs']
return self._snap_daemons(args, services).stdout
Expand Down
2 changes: 1 addition & 1 deletion snap/src/charmlibs/snap/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = '1.0.0.post0'
__version__ = '1.0.1'
8 changes: 8 additions & 0 deletions snap/tests/unit/test_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ def test_can_run_snap_daemon_commands(self, mock_subprocess: MagicMock):
capture_output=True,
)

foo.logs(num_lines='all')
mock_subprocess.assert_called_with(
['snap', 'logs', '-n=all', 'foo'],
text=True,
check=True,
capture_output=True,
)

foo.logs(services=['bar', 'baz'], num_lines=0) # falsey num_lines is ignored
mock_subprocess.assert_called_with(
['snap', 'logs', 'foo.bar', 'foo.baz'],
Expand Down
Loading