File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 113113)
114114
115115if TYPE_CHECKING :
116+ from typing import TextIO
117+
116118 from opentelemetry ._events import EventLoggerProvider
117119
118120 from .main import Logfire
@@ -159,6 +161,8 @@ class ConsoleOptions:
159161
160162 show_project_link : bool = True
161163 """Whether to print the URL of the Logfire project after initialization."""
164+ output : TextIO | None = None
165+ """The output stream to write console output to (default: stdout)."""
162166
163167
164168@dataclass
@@ -894,6 +898,7 @@ def add_span_processor(span_processor: SpanProcessor) -> None:
894898 include_tags = self .console .include_tags ,
895899 verbose = self .console .verbose ,
896900 min_log_level = self .console .min_log_level ,
901+ output = self .console .output ,
897902 )
898903 add_span_processor (SimpleSpanProcessor (console_span_exporter ))
899904 log_record_processors .append (SimpleLogRecordProcessor (ConsoleLogExporter (console_span_exporter )))
Original file line number Diff line number Diff line change 77import threading
88from collections .abc import Iterable , Sequence
99from contextlib import ExitStack
10+ from io import StringIO
1011from pathlib import Path
1112from time import sleep , time
1213from typing import Any
@@ -881,6 +882,19 @@ def test_config_serializable_console_false():
881882 assert GLOBAL_CONFIG .console is False
882883
883884
885+ def test_config_console_output_set ():
886+ output = StringIO ()
887+ logfire .configure (send_to_logfire = False , console = logfire .ConsoleOptions (output = output ))
888+ assert isinstance (GLOBAL_CONFIG .console , logfire .ConsoleOptions )
889+ assert GLOBAL_CONFIG .console .output is output
890+
891+ deserialize_config (serialize_config ())
892+ assert isinstance (GLOBAL_CONFIG .console , logfire .ConsoleOptions )
893+ assert GLOBAL_CONFIG .console .output is output
894+ logfire .info ('test' )
895+ assert 'test' in output .getvalue ()
896+
897+
884898def test_sanitize_project_name ():
885899 assert sanitize_project_name ('foo' ) == 'foo'
886900 assert sanitize_project_name ('FOO' ) == 'foo'
You can’t perform that action at this time.
0 commit comments