SwiftGUI_Logging 0.1.1__tar.gz → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SwiftGUI_Logging
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: A collection of helpful logging-functionality based on the logging package
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -79,11 +79,33 @@ if __name__ == '__main__':
79
79
 
80
80
  You'll find that the directory `Crashlogs` was created.
81
81
  After the program executes, the directory contains a file like
82
- `Crash_2026-02-24_16-16-38.log`.
82
+ `Crash_2026-02-24_16-33-52.log`.
83
83
 
84
84
  As you can see, the time of the crash was inserted into the
85
85
  filename, so that multiple crashlogs don't overwrite each other.
86
86
 
87
+ The file contains the most recent log-entries (from `logging.debug` and `logging.info`)
88
+ and the exception with full traceback:
89
+ ```log
90
+ 2026-02-24 16:33:49,940 - root - DEBUG - Test 0
91
+ 2026-02-24 16:33:50,197 - root - DEBUG - Test 1
92
+ 2026-02-24 16:33:50,451 - root - DEBUG - Test 2
93
+ 2026-02-24 16:33:50,704 - root - DEBUG - Test 3
94
+ 2026-02-24 16:33:50,958 - root - DEBUG - Test 4
95
+ 2026-02-24 16:33:51,214 - root - DEBUG - Test 5
96
+ 2026-02-24 16:33:51,469 - root - DEBUG - Test 6
97
+ 2026-02-24 16:33:51,723 - root - DEBUG - Test 7
98
+ 2026-02-24 16:33:51,979 - root - DEBUG - Test 8
99
+ 2026-02-24 16:33:52,235 - root - DEBUG - Test 9
100
+ 2026-02-24 16:33:52,490 - root - INFO - Crashing the program now
101
+ 2026-02-24 16:33:52,490 - root - ERROR - Traceback (most recent call last):
102
+ File "C:\Users\chees\PycharmProjects\SwiftGUI-Logging\tests\test.py", line 17, in <module>
103
+ main() # Execute program
104
+ File "C:\Users\chees\PycharmProjects\SwiftGUI-Logging\tests\test.py", line 13, in main
105
+ 1 / 0 # Cause a ZeroDivisionError, which crashes the program
106
+ ZeroDivisionError: division by zero
107
+ ```
108
+
87
109
  `sgl.Configs.exceptions_to_file` can do a bit more, but for most programs,
88
110
  the default configuration is fine.
89
111
 
@@ -63,11 +63,33 @@ if __name__ == '__main__':
63
63
 
64
64
  You'll find that the directory `Crashlogs` was created.
65
65
  After the program executes, the directory contains a file like
66
- `Crash_2026-02-24_16-16-38.log`.
66
+ `Crash_2026-02-24_16-33-52.log`.
67
67
 
68
68
  As you can see, the time of the crash was inserted into the
69
69
  filename, so that multiple crashlogs don't overwrite each other.
70
70
 
71
+ The file contains the most recent log-entries (from `logging.debug` and `logging.info`)
72
+ and the exception with full traceback:
73
+ ```log
74
+ 2026-02-24 16:33:49,940 - root - DEBUG - Test 0
75
+ 2026-02-24 16:33:50,197 - root - DEBUG - Test 1
76
+ 2026-02-24 16:33:50,451 - root - DEBUG - Test 2
77
+ 2026-02-24 16:33:50,704 - root - DEBUG - Test 3
78
+ 2026-02-24 16:33:50,958 - root - DEBUG - Test 4
79
+ 2026-02-24 16:33:51,214 - root - DEBUG - Test 5
80
+ 2026-02-24 16:33:51,469 - root - DEBUG - Test 6
81
+ 2026-02-24 16:33:51,723 - root - DEBUG - Test 7
82
+ 2026-02-24 16:33:51,979 - root - DEBUG - Test 8
83
+ 2026-02-24 16:33:52,235 - root - DEBUG - Test 9
84
+ 2026-02-24 16:33:52,490 - root - INFO - Crashing the program now
85
+ 2026-02-24 16:33:52,490 - root - ERROR - Traceback (most recent call last):
86
+ File "C:\Users\chees\PycharmProjects\SwiftGUI-Logging\tests\test.py", line 17, in <module>
87
+ main() # Execute program
88
+ File "C:\Users\chees\PycharmProjects\SwiftGUI-Logging\tests\test.py", line 13, in main
89
+ 1 / 0 # Cause a ZeroDivisionError, which crashes the program
90
+ ZeroDivisionError: division by zero
91
+ ```
92
+
71
93
  `sgl.Configs.exceptions_to_file` can do a bit more, but for most programs,
72
94
  the default configuration is fine.
73
95
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "SwiftGUI_Logging"
3
- version = "0.1.1"
3
+ version = "0.1.3"
4
4
  packages = [
5
5
  { include = "SwiftGUI_Logging", from = "src" }
6
6
  ]
@@ -59,7 +59,7 @@ def exceptions_to_file(
59
59
  # Add current datetime to filename
60
60
  actual_filepath = filepath.parent / (filepath.stem + dt.now().strftime(datetime_format) + filepath.suffix)
61
61
 
62
- with open(actual_filepath, "w") as f:
62
+ with open(actual_filepath, "a") as f:
63
63
  stream.seek(0)
64
64
  shutil.copyfileobj(stream, f)
65
65
 
@@ -20,6 +20,7 @@ class MemoryHandlerRotatingBuffer(logging.handlers.MemoryHandler):
20
20
  """
21
21
  super().__init__(capacity, flushLevel, target, flushOnClose=False)
22
22
  self.call_after_flushing = call_after_flushing if call_after_flushing else lambda *_:_
23
+ self._should_flush = False
23
24
 
24
25
  def shouldFlush(self, record):
25
26
  """
@@ -30,10 +31,17 @@ class MemoryHandlerRotatingBuffer(logging.handlers.MemoryHandler):
30
31
  if len(self.buffer) > self.capacity: # Remove 0th element so the buffer doesn't "overflow"
31
32
  self.buffer.pop(0)
32
33
 
33
- return record.levelno >= self.flushLevel
34
+ if record.levelno >= self.flushLevel:
35
+ self._should_flush = True
36
+ return True
37
+
38
+ return False
34
39
 
35
40
  def flush(self):
36
- super().flush()
37
- self.call_after_flushing()
41
+ super().flush() # Don't put this in the if, this is necessary due to Python-magic...
42
+
43
+ if self._should_flush:
44
+ self.call_after_flushing()
45
+ self._should_flush = False
38
46
 
39
47