@@ -710,6 +710,38 @@ def add_meaningless_arg(arg: str) -> None:
710710 for w in to_warn :
711711 warnings .warn (w , stacklevel = 2 )
712712
713+ @classmethod
714+ def get_active (cls ) -> ConsoleRenderer :
715+ """
716+ If *structlog* is configured to use `ConsoleRenderer`, it's returned.
717+
718+ It does not have to be the last processor.
719+
720+ Raises:
721+ NoConsoleRendererConfiguredError:
722+ If no ConsoleRenderer is found in the current configuration.
723+
724+ MultipleConsoleRenderersConfiguredError:
725+ If more than one is found in the current configuration. This is
726+ almost certainly a bug.
727+
728+ .. versionadded:: 25.5.0
729+ """
730+ from ._config import get_config
731+
732+ cr = None
733+ for p in get_config ()["processors" ]:
734+ if isinstance (p , ConsoleRenderer ):
735+ if cr is not None :
736+ raise MultipleConsoleRenderersConfiguredError
737+
738+ cr = p
739+
740+ if cr is None :
741+ raise NoConsoleRendererConfiguredError
742+
743+ return cr
744+
713745 @classmethod
714746 def get_default_column_styles (
715747 cls , colors : bool , force_colors : bool = False
@@ -744,6 +776,37 @@ def get_default_column_styles(
744776
745777 return _colorful_styles
746778
779+ @staticmethod
780+ def get_default_level_styles (colors : bool = True ) -> dict [str , str ]:
781+ """
782+ Get the default styles for log levels
783+
784+ This is intended to be used with `ConsoleRenderer`'s ``level_styles``
785+ parameter. For example, if you are adding custom levels in your
786+ home-grown :func:`~structlog.stdlib.add_log_level` you could do::
787+
788+ my_styles = ConsoleRenderer.get_default_level_styles()
789+ my_styles["EVERYTHING_IS_ON_FIRE"] = my_styles["critical"]
790+ renderer = ConsoleRenderer(level_styles=my_styles)
791+
792+ Args:
793+ colors:
794+ Whether to use colorful styles. This must match the *colors*
795+ parameter to `ConsoleRenderer`. Default: `True`.
796+ """
797+ styles : ColumnStyles
798+ styles = _colorful_styles if colors else _plain_styles
799+ return {
800+ "critical" : styles .level_critical ,
801+ "exception" : styles .level_exception ,
802+ "error" : styles .level_error ,
803+ "warn" : styles .level_warn ,
804+ "warning" : styles .level_warn ,
805+ "info" : styles .level_info ,
806+ "debug" : styles .level_debug ,
807+ "notset" : styles .level_notset ,
808+ }
809+
747810 def _configure_columns (self ) -> None :
748811 """
749812 Re-configure self._columns and self._default_column_formatter
@@ -865,37 +928,6 @@ def __call__(
865928
866929 return sio .getvalue ()
867930
868- @staticmethod
869- def get_default_level_styles (colors : bool = True ) -> dict [str , str ]:
870- """
871- Get the default styles for log levels
872-
873- This is intended to be used with `ConsoleRenderer`'s ``level_styles``
874- parameter. For example, if you are adding custom levels in your
875- home-grown :func:`~structlog.stdlib.add_log_level` you could do::
876-
877- my_styles = ConsoleRenderer.get_default_level_styles()
878- my_styles["EVERYTHING_IS_ON_FIRE"] = my_styles["critical"]
879- renderer = ConsoleRenderer(level_styles=my_styles)
880-
881- Args:
882- colors:
883- Whether to use colorful styles. This must match the *colors*
884- parameter to `ConsoleRenderer`. Default: `True`.
885- """
886- styles : ColumnStyles
887- styles = _colorful_styles if colors else _plain_styles
888- return {
889- "critical" : styles .level_critical ,
890- "exception" : styles .level_exception ,
891- "error" : styles .level_error ,
892- "warn" : styles .level_warn ,
893- "warning" : styles .level_warn ,
894- "info" : styles .level_info ,
895- "debug" : styles .level_debug ,
896- "notset" : styles .level_notset ,
897- }
898-
899931 @property
900932 def exception_formatter (self ) -> ExceptionRenderer :
901933 """
@@ -1019,38 +1051,6 @@ def force_colors(self, value: bool) -> None:
10191051
10201052 self ._configure_columns ()
10211053
1022- @classmethod
1023- def get_active (cls ) -> ConsoleRenderer :
1024- """
1025- If *structlog* is configured to use `ConsoleRenderer`, it's returned.
1026-
1027- It does not have to be the last processor.
1028-
1029- Raises:
1030- NoConsoleRendererConfiguredError:
1031- If no ConsoleRenderer is found in the current configuration.
1032-
1033- MultipleConsoleRenderersConfiguredError:
1034- If more than one is found in the current configuration. This is
1035- almost certainly a bug.
1036-
1037- .. versionadded:: 25.5.0
1038- """
1039- from ._config import get_config
1040-
1041- cr = None
1042- for p in get_config ()["processors" ]:
1043- if isinstance (p , ConsoleRenderer ):
1044- if cr is not None :
1045- raise MultipleConsoleRenderersConfiguredError
1046-
1047- cr = p
1048-
1049- if cr is None :
1050- raise NoConsoleRendererConfiguredError
1051-
1052- return cr
1053-
10541054 @property
10551055 def level_styles (self ) -> dict [str , str ]:
10561056 """
@@ -1153,6 +1153,22 @@ def timestamp_key(self, value: str) -> None:
11531153 self ._timestamp_key = value
11541154 self ._configure_columns ()
11551155
1156+ @property
1157+ def repr_native_str (self ) -> bool :
1158+ """
1159+ Whether native strings are passed through repr() in non-event values.
1160+
1161+ .. versionadded:: 25.5.0
1162+ """
1163+ return self ._repr_native_str
1164+
1165+ @repr_native_str .setter
1166+ def repr_native_str (self , value : bool ) -> None :
1167+ """
1168+ .. versionadded:: 25.5.0
1169+ """
1170+ self ._repr_native_str = value
1171+
11561172
11571173_SENTINEL = object ()
11581174
0 commit comments