logging
scrapli.logging
ScrapliFileHandler
¶
Bases: FileHandler_
Source code in scrapli/logging.py
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
__init__(filename: str, mode: str = 'a', encoding: Optional[str] = None, delay: bool = False) -> None
¶
Handle "buffering" log read messages for logging.FileHandler
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
name of file to create |
required |
mode |
str
|
file mode |
'a'
|
encoding |
Optional[str]
|
encoding to use for file |
None
|
delay |
bool
|
actually not sure what this is for :) |
False
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in scrapli/logging.py
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 |
|
emit(record: LogRecord_) -> None
¶
Override standard library FileHandler.emit to "buffer" subsequent read messages
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
LogRecord_
|
log record to check |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in scrapli/logging.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
emit_buffered() -> None
¶
Emit a buffered read message to the FileHandler
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ScrapliException
|
should never be raised! |
Source code in scrapli/logging.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
ScrapliFormatter
¶
Bases: Formatter_
Source code in scrapli/logging.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 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 |
|
__init__(log_header: bool = True, caller_info: bool = False) -> None
¶
Scrapli's opinionated custom log formatter class
Only applied/used when explicitly requested by the user, otherwise we leave logging up to the user as any library should!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log_header |
bool
|
add the "header" row to logging output (or not) |
True
|
caller_info |
bool
|
add caller (module/package/line) info to log output |
False
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in scrapli/logging.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
formatMessage(record: LogRecord_) -> str
¶
Override standard library logging Formatter.formatMessage
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
LogRecord_
|
LogRecord to format |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
log string to emit |
Source code in scrapli/logging.py
80 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 |
|
enable_basic_logging(file: Union[str, bool] = False, level: str = 'info', caller_info: bool = False, buffer_log: bool = True, mode: str = 'write') -> None
¶
Enable opinionated logging for scrapli
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
Union[str, bool]
|
True to output to default log path ("scrapli.log"), otherwise string path to write log file to |
False
|
level |
str
|
string name of logging level to use, i.e. "info", "debug", etc. |
'info'
|
caller_info |
bool
|
add info about module/function/line in the log entry |
False
|
buffer_log |
bool
|
buffer log read outputs |
True
|
mode |
str
|
string of "write" or "append" |
'write'
|
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ScrapliException
|
if invalid mode is passed |
Source code in scrapli/logging.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
get_instance_logger(instance_name: str, host: str = '', port: int = 0, uid: str = '') -> LoggerAdapterT
¶
Get an adapted logger instance for a given instance (driver/channel/transport)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance_name |
str
|
logger/instance name, i.e. "scrapli.driver" |
required |
host |
str
|
host to add to logging extras if applicable |
''
|
port |
int
|
port to add to logging extras if applicable |
0
|
uid |
str
|
unique id for a logging instance |
''
|
Returns:
Name | Type | Description |
---|---|---|
LoggerAdapterT |
LoggerAdapterT
|
adapter logger for the instance |
Source code in scrapli/logging.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|