entry
entry
#
Entry — one line of a log, and Progress, one that counts.
- A line.
info("…")makes an entry complete as it stands: a level, a message, named fields, and when it happened. Itskindsays what the message is, so a renderer can show it as such: prose, a shell command, or a program's output (which may carry ANSI colour codes). - A scope.
withon an entry makes it the ambient parent for the block: entries made inside sit beneath it, and it endsdone, orfailedwith the exception's text. - A count.
Progressaddsdone/total: iterating it runs each element as aturn— numbered, ambient for its block, counted when it ends — andadvanceandupdate(done=…)count from any thread that holds it.
Every change goes through the entry's Log, which bumps revision and
tells the sinks. An entry with no log — what the verbs return when nothing is
listening — accepts every call and records nothing.
INERT = Entry(None, '', None, 'info', '', {}, None)
module-attribute
#
What the verbs return when nothing is listening: it accepts every call and records nothing.
ambient = ContextVar('cg_logging_ambient', default=None)
module-attribute
#
The entry new entries sit beneath; None when nothing is listening.
Entry
#
One line of a log; with makes it a scope.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Unique within its log; |
|
parent |
The id of the entry this one sits beneath, |
|
level |
|
|
message |
What the line says. |
|
kind |
Kind
|
What the message is: |
fields |
Named values the line carries. |
|
done |
int | None
|
How many units are done, for a |
total |
int | None
|
How many there are, for a |
iteration |
int | None
|
The enclosing loop's iteration when the entry was last logged. |
started |
When the entry was made, as |
|
ended |
float | None
|
When the scope ended, or |
status |
Status
|
|
error |
str | None
|
The exception text of a failed scope: its type and message, then each of its notes on a line of its own. |
revision |
How many times the entry has changed since it was made. |
Source code in capturegraph-lib/capturegraph/logging/entry.py
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 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 178 179 180 181 182 183 184 | |
elapsed
property
#
Seconds the entry has been open, or was open for.
__enter__()
#
Open the scope: entries logged in the block sit beneath this one.
Source code in capturegraph-lib/capturegraph/logging/entry.py
__exit__(kind, error, traceback)
#
Close the scope as done, or failed carrying the exception's text.
Source code in capturegraph-lib/capturegraph/logging/entry.py
__init__(log, id, parent, level, message, fields, iteration, kind='text')
#
An entry of log beneath parent; the verbs make these, not callers.
Source code in capturegraph-lib/capturegraph/logging/entry.py
__repr__()
#
json()
#
The entry as the wire shape every renderer reads.
Source code in capturegraph-lib/capturegraph/logging/entry.py
update(message=None, *, done=None, **fields)
#
Change the message, the count and the named fields in one revision.
Source code in capturegraph-lib/capturegraph/logging/entry.py
Progress
#
Bases: Entry
An entry that counts; iterate it, or advance/update it by hand.
for batch in cg.logging.progress(batches, label="Training"):
...
with cg.logging.progress(total=len(jobs), label="Rendering") as bar:
for job in jobs:
render(job)
bar.advance()
Source code in capturegraph-lib/capturegraph/logging/entry.py
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 232 233 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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
__init__(log, id, parent, message, fields, iteration, *, total, iterable)
#
A count of total beneath parent, over iterable when given.
Source code in capturegraph-lib/capturegraph/logging/entry.py
__iter__()
#
The elements, each an iteration this entry is the ambient parent of.
Raises:
| Type | Description |
|---|---|
TypeError
|
If the progress was made without an iterable. |
Source code in capturegraph-lib/capturegraph/logging/entry.py
advance(count=1)
#
turn()
#
One iteration as a block: numbered, the ambient parent inside, counted on its way out.
A block that raises or is broken out of is not counted. Iterating does
this per element; call it yourself when the elements come to you one
at a time, as a pmap worker's do.
Source code in capturegraph-lib/capturegraph/logging/entry.py
describe(error)
#
Type: message, then each note the exception carries on its own line.
Source code in capturegraph-lib/capturegraph/logging/entry.py
listening()
#
The ambient parent and the log it belongs to, or None when nothing is listening.