instruktai-python-logger 0.4.2__tar.gz → 0.4.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/PKG-INFO +1 -1
  2. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instrukt_ai_logging/logging.py +17 -1
  3. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instruktai_python_logger.egg-info/PKG-INFO +1 -1
  4. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/pyproject.toml +1 -1
  5. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/tests/test_log_aggregation.py +26 -0
  6. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/README.md +0 -0
  7. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instrukt_ai_logging/__init__.py +0 -0
  8. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instrukt_ai_logging/cli.py +0 -0
  9. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instrukt_ai_logging/install.py +0 -0
  10. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instrukt_ai_logging/py.typed +0 -0
  11. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instruktai_python_logger.egg-info/SOURCES.txt +0 -0
  12. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instruktai_python_logger.egg-info/dependency_links.txt +0 -0
  13. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instruktai_python_logger.egg-info/entry_points.txt +0 -0
  14. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instruktai_python_logger.egg-info/requires.txt +0 -0
  15. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/instruktai_python_logger.egg-info/top_level.txt +0 -0
  16. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/setup.cfg +0 -0
  17. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/tests/test_cli_follow.py +0 -0
  18. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/tests/test_configure_logging.py +0 -0
  19. {instruktai_python_logger-0.4.2 → instruktai_python_logger-0.4.4}/tests/test_trace_logging.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: instruktai-python-logger
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Centralized logging utilities for Python services.
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -564,6 +564,12 @@ def iter_recent_log_lines_merged(files: Iterable[Path], since: timedelta) -> Ite
564
564
  entries stay adjacent to their parent). The resulting per-file streams are
565
565
  merged via a k-way heap merge, producing a single chronologically-ordered
566
566
  output stream.
567
+
568
+ Files whose mtime falls before the cutoff are skipped entirely — no line
569
+ inside them can be newer than the file itself, so reading them only burns
570
+ I/O. This matters for log directories with large rotation history or
571
+ sibling streams (git-wrapper.log, etc.) the caller didn't explicitly
572
+ request via `--logs`.
567
573
  """
568
574
  cutoff = _now_utc() - since
569
575
 
@@ -588,6 +594,16 @@ def iter_recent_log_lines_merged(files: Iterable[Path], since: timedelta) -> Ite
588
594
  finally:
589
595
  f.close()
590
596
 
591
- streams = [_file_stream(p) for p in files]
597
+ eligible: list[Path] = []
598
+ for path in files:
599
+ try:
600
+ mtime = datetime.fromtimestamp(path.stat().st_mtime, tz=timezone.utc)
601
+ except OSError:
602
+ continue
603
+ if mtime < cutoff:
604
+ continue
605
+ eligible.append(path)
606
+
607
+ streams = [_file_stream(p) for p in eligible]
592
608
  for _, line in heapq.merge(*streams, key=lambda item: item[0]):
593
609
  yield line
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: instruktai-python-logger
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Centralized logging utilities for Python services.
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "instruktai-python-logger"
7
- version = "0.4.2"
7
+ version = "0.4.4"
8
8
  description = "Centralized logging utilities for Python services."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -111,6 +111,32 @@ def test_iter_recent_log_lines_merged_respects_since_cutoff(app_log_dir: Path) -
111
111
  assert "fresh" in lines[0]
112
112
 
113
113
 
114
+ def test_iter_recent_log_lines_merged_skips_files_with_mtime_before_cutoff(
115
+ app_log_dir: Path,
116
+ ) -> None:
117
+ import os
118
+ from datetime import datetime, timezone
119
+
120
+ fresh = app_log_dir / "demo-app.log"
121
+ fresh.write_text(
122
+ f"{_now_iso(-1)} level=INFO logger=demo.daemon msg=fresh\n",
123
+ encoding="utf-8",
124
+ )
125
+ stale = app_log_dir / "stale.log"
126
+ stale.write_text(
127
+ f"{_now_iso(-1)} level=INFO logger=stale msg=stale-but-line-looks-recent\n",
128
+ encoding="utf-8",
129
+ )
130
+ # Force stale.log's mtime to 1 day ago — older than --since=10m cutoff.
131
+ one_day_ago = (datetime.now(tz=timezone.utc) - timedelta(days=1)).timestamp()
132
+ os.utime(stale, (one_day_ago, one_day_ago))
133
+
134
+ files = resolve_log_files("demo-app")
135
+ lines = list(iter_recent_log_lines_merged(files, since=timedelta(minutes=10)))
136
+ msgs = [line.strip().rsplit("=", 1)[-1] for line in lines]
137
+ assert msgs == ["fresh"]
138
+
139
+
114
140
  def test_iter_recent_log_lines_merged_keeps_continuation_lines_with_parent(
115
141
  app_log_dir: Path,
116
142
  ) -> None: