Reference
Crash Catcher
Error logger/crash reporter decorator
crash_catcher(filename, message, title, postamble=None, overwrite=True, **extra)
Catch crash (uncaught exception) and create a crash dump file on error named filename
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str | Path | PathLike
|
name of crash dump file to create |
required |
message |
str
|
message to print to stderr upon crash |
required |
title |
str
|
title to print to start of crash dump file |
required |
postamble |
str | None
|
optional message printed to stderr after crash dump file is created. |
None
|
overwrite |
bool
|
if True, overwrite existing file, otherwise increment filename until a non-existent filename is found |
True
|
extra |
Any
|
If kwargs provided, any additional arguments to the function will be printed to the crash file. |
{}
|
This decorator should be applied to the main function of the program.
The message, title, and postamble arguments may include the template {filename} which
will be replaced with the actual filename of the crash log. For example, if overwrite=False
and the crash file crash_catcher.log
already exists, the filename will be incremented to
crash_catcher (1).log
, crash_catcher (2).log
, and so on until a non-existent filename is found.
This filename will be used to render the {filename} template.
Source code in crash_catcher/crash_catcher.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
register_crash_callback(func, message=None)
Register callback to be run if crash is caught.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable[[], None]
|
callable that will be called (with no args) by crash_catcher |
required |
message |
str | None
|
optional message |
None
|
Returns:
Type | Description |
---|---|
int
|
id for callback which may be used with unregister_crash_callback() to remove the callback. |
Multiple callabacks may be registered by calling this function repeatedly.
Callbacks will be executed in order they are registered.
Source code in crash_catcher/crash_catcher.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
set_crash_data(key_, data)
Set data to be printed in crash log
Source code in crash_catcher/crash_catcher.py
38 39 40 |
|
unregister_crash_callback(callback_id)
Unregister a crash callback previously registered with register_crash_callback().
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callback_id |
int
|
the ID of the callback to unregister as returned by register_crash_callback() |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if the callback_id is not valid |
Note: After a callback is unregisterd, it will not be called if a crash is caught.
Source code in crash_catcher/crash_catcher.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|