Log rich content to the terminal. Args: objects (positional args): Objects to log to the terminal. sep (str, optional): String to write between print data. Defaults to " ". end (str, optional): String to write at end of print data. Defaults to "\\\\n".
(
self,
*objects: Any,
sep: str = " ",
end: str = "\n",
style: Optional[Union[str, Style]] = None,
justify: Optional[JustifyMethod] = None,
emoji: Optional[bool] = None,
markup: Optional[bool] = None,
highlight: Optional[bool] = None,
log_locals: bool = False,
_stack_offset: int = 1,
)
| 1945 | return frame_info.filename, frame_info.lineno, frame_info.frame.f_locals |
| 1946 | |
| 1947 | def log( |
| 1948 | self, |
| 1949 | *objects: Any, |
| 1950 | sep: str = " ", |
| 1951 | end: str = "\n", |
| 1952 | style: Optional[Union[str, Style]] = None, |
| 1953 | justify: Optional[JustifyMethod] = None, |
| 1954 | emoji: Optional[bool] = None, |
| 1955 | markup: Optional[bool] = None, |
| 1956 | highlight: Optional[bool] = None, |
| 1957 | log_locals: bool = False, |
| 1958 | _stack_offset: int = 1, |
| 1959 | ) -> None: |
| 1960 | """Log rich content to the terminal. |
| 1961 | |
| 1962 | Args: |
| 1963 | objects (positional args): Objects to log to the terminal. |
| 1964 | sep (str, optional): String to write between print data. Defaults to " ". |
| 1965 | end (str, optional): String to write at end of print data. Defaults to "\\\\n". |
| 1966 | style (Union[str, Style], optional): A style to apply to output. Defaults to None. |
| 1967 | justify (str, optional): One of "left", "right", "center", or "full". Defaults to ``None``. |
| 1968 | emoji (Optional[bool], optional): Enable emoji code, or ``None`` to use console default. Defaults to None. |
| 1969 | markup (Optional[bool], optional): Enable markup, or ``None`` to use console default. Defaults to None. |
| 1970 | highlight (Optional[bool], optional): Enable automatic highlighting, or ``None`` to use console default. Defaults to None. |
| 1971 | log_locals (bool, optional): Boolean to enable logging of locals where ``log()`` |
| 1972 | was called. Defaults to False. |
| 1973 | _stack_offset (int, optional): Offset of caller from end of call stack. Defaults to 1. |
| 1974 | """ |
| 1975 | if not objects: |
| 1976 | objects = (NewLine(),) |
| 1977 | |
| 1978 | render_hooks = self._render_hooks[:] |
| 1979 | |
| 1980 | with self: |
| 1981 | renderables = self._collect_renderables( |
| 1982 | objects, |
| 1983 | sep, |
| 1984 | end, |
| 1985 | justify=justify, |
| 1986 | emoji=emoji, |
| 1987 | markup=markup, |
| 1988 | highlight=highlight, |
| 1989 | ) |
| 1990 | if style is not None: |
| 1991 | renderables = [Styled(renderable, style) for renderable in renderables] |
| 1992 | |
| 1993 | filename, line_no, locals = self._caller_frame_info(_stack_offset) |
| 1994 | link_path = None if filename.startswith("<") else os.path.abspath(filename) |
| 1995 | path = filename.rpartition(os.sep)[-1] |
| 1996 | if log_locals: |
| 1997 | from .scope import render_scope |
| 1998 | |
| 1999 | locals_map = { |
| 2000 | key: value |
| 2001 | for key, value in locals.items() |
| 2002 | if not key.startswith("__") |
| 2003 | } |
| 2004 | renderables.append(render_scope(locals_map, title="[i]locals")) |