Skip to content

More verbose console logging fixes #1072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged

Conversation

alexmojaki
Copy link
Contributor

Example script:

import datetime
import decimal

import logfire

logfire.configure(console=logfire.ConsoleOptions(verbose=True))

logfire.info('hi', d=datetime.datetime.now(), v=decimal.Decimal('1.0'))
logfire.info('hi', x=None)

With this PR:

11:04:25.386 hi
             │ scratch_1502.py:9 info
             │ d=2025-05-14T13:04:25.366639
             │ v=1.0
11:04:25.386 hi
             │ scratch_1502.py:10 info
             │ x=None

Before:

11:04:58.030 hi
             │ scratch_1502.py:8 info
             │ d=[
             │       '2',
             │       '0',
             │       '2',
             │       '5',
             │       '-',
             │       '0',
             │       '5',
             │       '-',
             │       '1',
             │       '4',
             │       'T',
             │       '1',
             │       '3',
             │       ':',
             │       '0',
             │       '4',
             │       ':',
             │       '5',
             │       '8',
             │       '.',
             │       '0',
             │       '1',
             │       '0',
             │       '7',
             │       '1',
             │       '4',
             │   ]
             │ v=[
             │       '1',
             │       '.',
             │       '0',
             │   ]
11:04:58.030 hi
             │ scratch_1502.py:9 info
Exception while exporting Span.
Traceback (most recent call last):
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/opentelemetry/sdk/trace/export/__init__.py", line 114, in on_end
    self.span_exporter.export((span,))
  File "/Users/alex/work/logfire/logfire/_internal/exporters/console.py", line 148, in export
    self.export_record(Record.from_span(span))
  File "/Users/alex/work/logfire/logfire/_internal/exporters/console.py", line 417, in export_record
    self._print_span(span)
  File "/Users/alex/work/logfire/logfire/_internal/exporters/console.py", line 181, in _print_span
    self._print_arguments(span, indent_str)
  File "/Users/alex/work/logfire/logfire/_internal/exporters/console.py", line 268, in _print_arguments
    value = json_args_value_formatter(value, schema=schema)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/logfire/_internal/json_formatter.py", line 61, in __call__
    self._format(indent_current, True, value, schema)
  File "/Users/alex/work/logfire/logfire/_internal/json_formatter.py", line 73, in _format
    self._format_list_like('[', ']', indent_current, value, schema)
  File "/Users/alex/work/logfire/logfire/_internal/json_formatter.py", line 132, in _format_list_like
    for i, v in enumerate(value):
                ^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable

@alexmojaki alexmojaki enabled auto-merge (squash) May 14, 2025 11:07
@alexmojaki alexmojaki merged commit b061c23 into main May 14, 2025
14 checks passed
@alexmojaki alexmojaki deleted the alex/console-json-other-types branch May 14, 2025 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant