You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To log a message with a variable level you can use `logfire.log`, e.g. `logfire.log('info', 'This is an info log')` is equivalent to `logfire.info('This is an info log')`.
262
254
263
255
Spans are level `info` by default. You can change this with the `_level` argument, e.g. `with logfire.span('This is a debug span', _level='debug'):`. You can also change the level after the span has started but before it's finished with [`span.set_level`][logfire.LogfireSpan.set_level], e.g:
@@ -270,3 +262,44 @@ with logfire.span('Doing a thing') as span:
270
262
```
271
263
272
264
If a span finishes with an unhandled exception, then in addition to recording a traceback as described above, the span's log level will be set to `error`. This will not happen when using the [`span.record_exception`][logfire.LogfireSpan.record_exception] method.
265
+
266
+
To skip creating logs/spans below a certain level, use the [`min_level`][logfire.configure(min_level)] argument to
267
+
`logfire.configure`, e.g:
268
+
269
+
```python
270
+
import logfire
271
+
272
+
logfire.configure(min_level='info')
273
+
```
274
+
275
+
For spans, this only applies when `_level` is explicitly specified in `logfire.span`.
276
+
Setting the level after will be ignored by this.
277
+
If a span is not created because of the minimum level, this has no effect on parents or children.
278
+
For example, this code:
279
+
280
+
```python
281
+
import logfire
282
+
283
+
logfire.configure(min_level='info')
284
+
285
+
with logfire.span('root') as root:
286
+
root.set_level('debug') # (1)!
287
+
with logfire.span('debug span excluded', _level='debug'): # (2)!
288
+
logfire.info('info message')
289
+
```
290
+
291
+
1. This span has already been created with the default level of `info`, so `min_level` won't affect it.
292
+
It's also logged to the console because that happens at creation time.
293
+
But it will show in the Live view as having level `debug`.
294
+
2. This span is not created because its level is below the minimum.
295
+
That makes this line a complete no-op.
296
+
297
+
creates, logs, and sends the `root` span and the `info message` log, with the log being a direct child of the span.
298
+
299
+
To set the minimum level for console logging only (`info` by default):
0 commit comments