logler 1.0.7__cp311-cp311-win_amd64.whl

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.
logler/watcher.py ADDED
@@ -0,0 +1,55 @@
1
+ """
2
+ File watching with regex pattern matching.
3
+ """
4
+
5
+ import asyncio
6
+ import fnmatch
7
+ from pathlib import Path
8
+ from watchdog.observers import Observer
9
+ from watchdog.events import FileSystemEventHandler
10
+
11
+ from rich.console import Console
12
+
13
+
14
+ class LogFileHandler(FileSystemEventHandler):
15
+ """Handle log file events."""
16
+
17
+ def __init__(self, pattern: str, callback):
18
+ self.pattern = pattern
19
+ self.callback = callback
20
+
21
+ def on_created(self, event):
22
+ """Handle file creation."""
23
+ if not event.is_directory:
24
+ path = Path(event.src_path)
25
+ if fnmatch.fnmatch(path.name, self.pattern):
26
+ self.callback(path)
27
+
28
+
29
+ class FileWatcher:
30
+ """Watch for new log files matching a pattern."""
31
+
32
+ def __init__(self, pattern: str, directory: str = ".", recursive: bool = False):
33
+ self.pattern = pattern
34
+ self.directory = Path(directory)
35
+ self.recursive = recursive
36
+ self.console = Console()
37
+
38
+ async def watch(self):
39
+ """Start watching for files."""
40
+ observer = Observer()
41
+
42
+ def on_file_created(path: Path):
43
+ self.console.print(f"[green]✓[/green] New file: [cyan]{path}[/cyan]")
44
+
45
+ handler = LogFileHandler(self.pattern, on_file_created)
46
+ observer.schedule(handler, str(self.directory), recursive=self.recursive)
47
+ observer.start()
48
+
49
+ try:
50
+ while True:
51
+ await asyncio.sleep(1)
52
+ except KeyboardInterrupt:
53
+ observer.stop()
54
+
55
+ observer.join()
logler/web/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """
2
+ Web interface for Logler.
3
+ """