diff --git a/changelog/index.html b/changelog/index.html index a0b27f0..762d33f 100644 --- a/changelog/index.html +++ b/changelog/index.html @@ -345,6 +345,21 @@ + +
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
poetry
to version 2.0.0Formatter
TelegramFormatter
from [%H:%M:%S]
to %H:%M:%S
LoggingAdapterHandler
where the attributes filename
, function
, and line
were not set for the Record
objectRecord
class: filename
, line
, basename
, relpath
, function
template
) for the Formatter
class, the relative path to the file and line are displayedanyio
pip install tinylogging\n
"},{"location":"#usage","title":"Usage","text":""},{"location":"#new-logger","title":"New logger","text":"from tinylogging import Logger, Level\n\nlogger = Logger(name=\"my_logger\", level=Level.DEBUG)\n
"},{"location":"#logging-messages","title":"Logging messages","text":"logger.info(\"This is an info message.\")\nlogger.error(\"This is an error message.\")\nlogger.debug(\"This is a debug message.\")\n
"},{"location":"#logging-to-a-file","title":"Logging to a file","text":"from tinylogging import FileHandler\n\nfile_handler = FileHandler(file_name=\"app.log\", level=Level.WARNING)\nlogger.handlers.add(file_handler)\n\nlogger.warning(\"This warning will be logged to both console and file.\")\n
"},{"location":"#custom-formatting","title":"Custom formatting","text":"from tinylogging import Formatter\n\nformatter = Formatter(template=\"{time} - {name} - {level} - {message}\", colorize=False)\nlogger = Logger(name=\"custom_logger\", formatter=formatter)\nlogger.info(\"This log message uses a custom format.\")\n
"},{"location":"#disabling-logging","title":"Disabling logging","text":"logger.disable()\nlogger.info(\"This message will not be logged.\")\nlogger.enable()\n
"},{"location":"#async-support","title":"Async support","text":"import asyncio\nfrom tinylogging import AsyncLogger, AsyncFileHandler\n\n\nasync def main():\n logger = AsyncLogger(name=\"async_logger\")\n\n file_handler = AsyncFileHandler(file_name=\"app.log\")\n logger.handlers.add(file_handler)\n\n await logger.info(\"This is an info message.\")\n await logger.error(\"This is an error message.\")\n await logger.debug(\"This is a debug message.\")\n\n\nif __name__ == \"__main__\":\n asyncio.run(main)\n
"},{"location":"#license","title":"License","text":"This project is licensed under the MIT License.
"},{"location":"api/","title":"API reference","text":""},{"location":"api/#tinylogging","title":"tinylogging","text":""},{"location":"api/#tinylogging.AsyncLogger","title":"AsyncLogger","text":""},{"location":"api/#tinylogging.AsyncLogger.__init__","title":"__init__","text":"__init__(name: str, level: Level = NOTSET, formatter: Formatter = Formatter(), handlers: set[BaseAsyncHandler] = set()) -> None\n
Initializes an asynchronous logger.
Parameters:
Name Type Description Defaultname
str
The name of the logger.
requiredlevel
Level
The logging level. Defaults to Level.NOTSET.
NOTSET
formatter
Formatter
The formatter for log messages. Defaults to Formatter().
Formatter()
handlers
set[BaseAsyncHandler]
A set of handlers for the logger. Defaults to an empty set.
set()
"},{"location":"api/#tinylogging.AsyncLogger.log","title":"log async
","text":"log(message: str, level: Level) -> None\n
Logs a message at the specified level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
requiredlevel
Level
The level at which to log the message.
required"},{"location":"api/#tinylogging.AsyncLogger.trace","title":"traceasync
","text":"trace(message: str) -> None\n
Logs a message with TRACE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.debug","title":"debugasync
","text":"debug(message: str) -> None\n
Logs a message with DEBUG level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.info","title":"infoasync
","text":"info(message: str) -> None\n
Logs a message with INFO level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.notice","title":"noticeasync
","text":"notice(message: str) -> None\n
Logs a message with NOTICE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.warning","title":"warningasync
","text":"warning(message: str) -> None\n
Logs a message with WARNING level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.error","title":"errorasync
","text":"error(message: str) -> None\n
Logs a message with ERROR level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.critical","title":"criticalasync
","text":"critical(message: str) -> None\n
Logs a message with CRITICAL level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.enable","title":"enable","text":"enable() -> None\n
Enables the logger.
"},{"location":"api/#tinylogging.AsyncLogger.disable","title":"disable","text":"disable() -> None\n
Disables the logger.
"},{"location":"api/#tinylogging.AsyncFileHandler","title":"AsyncFileHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for writing log records to a file.
"},{"location":"api/#tinylogging.AsyncFileHandler.__init__","title":"__init__","text":"__init__(file_name: str, level: Level = NOTSET, formatter: Formatter = Formatter(colorize=False)) -> None\n
Initializes the AsyncFileHandler.
Parameters:
Name Type Description Defaultfile_name
str
The name of the file to write log records to.
requiredlevel
Level
The logging level threshold for this handler.
NOTSET
formatter
Formatter
The formatter instance to format log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.AsyncFileHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.AsyncStreamHandler","title":"AsyncStreamHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for streaming log records.
"},{"location":"api/#tinylogging.AsyncStreamHandler.__init__","title":"__init__","text":"__init__(formatter: Formatter = Formatter(), level: Level = NOTSET, stream: Optional[AsyncFile[str]] = None) -> None\n
Initializes the AsyncStreamHandler.
Parameters:
Name Type Description Defaultformatter
Formatter
The formatter instance to format log records.
Formatter()
level
Level
The logging level threshold for this handler.
NOTSET
stream
Optional[AsyncFile[str]]
The stream to write log records to.
None
"},{"location":"api/#tinylogging.AsyncStreamHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the stream.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.AsyncTelegramHandler","title":"AsyncTelegramHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for sending log records to a Telegram chat.
"},{"location":"api/#tinylogging.AsyncTelegramHandler.__init__","title":"__init__","text":"__init__(token: str, chat_id: int | str, message_thread_id: Optional[int] = None, ignore_errors: bool = False, **kwargs: Any) -> None\n
Initializes the AsyncTelegramHandler.
Parameters:
Name Type Description Defaulttoken
str
The Telegram bot token.
requiredchat_id
int | str
The chat ID to send log records to.
requiredmessage_thread_id
Optional[int]
The message thread ID (optional).
None
ignore_errors
bool
Whether to ignore errors during sending.
False
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.AsyncTelegramHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.BaseAsyncHandler","title":"BaseAsyncHandler","text":" Bases: ABC
Base class for all async handlers.
"},{"location":"api/#tinylogging.BaseAsyncHandler.__init__","title":"__init__","text":"__init__(formatter: Formatter = Formatter(), level: Level = NOTSET) -> None\n
Initializes the BaseAsyncHandler.
Parameters:
Name Type Description Defaultformatter
Formatter
The formatter instance to format log records.
Formatter()
level
Level
The logging level threshold for this handler.
NOTSET
"},{"location":"api/#tinylogging.BaseAsyncHandler.emit","title":"emit abstractmethod
async
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
requiredRaises:
Type DescriptionNotImplementedError
This method should be overridden by subclasses.
"},{"location":"api/#tinylogging.BaseAsyncHandler.handle","title":"handleasync
","text":"handle(record: Record) -> None\n
Handle a log record if it meets the logging level threshold.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.Formatter","title":"Formatter","text":""},{"location":"api/#tinylogging.Formatter.__init__","title":"__init__","text":"__init__(time_format: str = '[%H:%M:%S]', template: str = '{time} | {level} | {relpath}:{line} | {message}', colorize: bool = True) -> None\n
Initializes the Formatter instance.
Parameters:
Name Type Description Defaulttime_format
str
The format for the timestamp in log messages.
'[%H:%M:%S]'
template
str
The template for formatting log messages.
'{time} | {level} | {relpath}:{line} | {message}'
colorize
bool
Whether to colorize the log messages.
True
"},{"location":"api/#tinylogging.Formatter.format","title":"format","text":"format(record: Record) -> str\n
Formats a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to format.
requiredReturns:
Name Type Descriptionstr
str
The formatted log message.
"},{"location":"api/#tinylogging.Level","title":"Level","text":" Bases: IntEnum
Enumeration for logging levels.
Attributes:
Name Type DescriptionNOTSET
No level set.
TRACE
Trace level for detailed debugging.
DEBUG
Debug level for general debugging.
INFO
Informational messages.
NOTICE
Notice level for normal but significant conditions.
WARNING
Warning level for potentially harmful situations.
ERROR
Error level for error events.
CRITICAL
Critical level for severe error events.
"},{"location":"api/#tinylogging.Record","title":"Recorddataclass
","text":"Represents a log record.
Attributes:
Name Type Descriptionmessage
str
The log message.
level
Level
The log level.
name
str
The name of the logger.
time
datetime
The time the log record was created.
filename
str
The name of the file where the log record was created.
line
int
The line number in the file where the log record was created.
function
str
The function name where the log record was created.
"},{"location":"api/#tinylogging.Record.basename","title":"basenameproperty
","text":"basename: str\n
Gets the base name of the file where the log record was created.
Returns:
Name Type Descriptionstr
str
The base name of the file.
"},{"location":"api/#tinylogging.Record.relpath","title":"relpathproperty
","text":"relpath: str\n
Gets the relative path of the file where the log record was created.
Returns:
Name Type Descriptionstr
str
The relative path of the file.
"},{"location":"api/#tinylogging.Record.__post_init__","title":"__post_init__","text":"__post_init__() -> None\n
Initializes additional attributes after the dataclass is created.
Raises:
Type DescriptionRuntimeError
If the stack frame cannot be retrieved.
"},{"location":"api/#tinylogging.Record.to_dict","title":"to_dict","text":"to_dict() -> dict[str, Any]\n
Converts the log record to a dictionary.
Returns:
Name Type Descriptiondict
dict[str, Any]
A dictionary representation of the log record.
"},{"location":"api/#tinylogging.Logger","title":"Logger","text":""},{"location":"api/#tinylogging.Logger.__init__","title":"__init__","text":"__init__(name: str, level: Level = NOTSET, formatter: Formatter = Formatter(), handlers: set[BaseHandler] = set()) -> None\n
Initializes a new Logger instance.
Parameters:
Name Type Description Defaultname
str
The name of the logger.
requiredlevel
Level
The logging level. Defaults to Level.NOTSET.
NOTSET
formatter
Formatter
The formatter for log messages. Defaults to Formatter().
Formatter()
handlers
set[BaseHandler]
A set of handlers for the logger. Defaults to an empty set.
set()
"},{"location":"api/#tinylogging.Logger.log","title":"log","text":"log(message: str, level: Level) -> None\n
Logs a message with the specified logging level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
requiredlevel
Level
The logging level for the message.
required"},{"location":"api/#tinylogging.Logger.trace","title":"trace","text":"trace(message: str) -> None\n
Logs a message with TRACE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.debug","title":"debug","text":"debug(message: str) -> None\n
Logs a message with DEBUG level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.info","title":"info","text":"info(message: str) -> None\n
Logs a message with INFO level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.notice","title":"notice","text":"notice(message: str) -> None\n
Logs a message with NOTICE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.warning","title":"warning","text":"warning(message: str) -> None\n
Logs a message with WARNING level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.error","title":"error","text":"error(message: str) -> None\n
Logs a message with ERROR level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.critical","title":"critical","text":"critical(message: str) -> None\n
Logs a message with CRITICAL level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.enable","title":"enable","text":"enable() -> None\n
Enables the logger.
"},{"location":"api/#tinylogging.Logger.disable","title":"disable","text":"disable() -> None\n
Disables the logger.
"},{"location":"api/#tinylogging.BaseHandler","title":"BaseHandler","text":" Bases: ABC
Abstract base class for all handlers.
Parameters:
Name Type Description Defaultformatter
Formatter
Formatter instance to format the log records.
Formatter()
level
Level
Logging level for the handler.
NOTSET
"},{"location":"api/#tinylogging.BaseHandler.emit","title":"emit abstractmethod
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.BaseHandler.handle","title":"handle","text":"handle(record: Record) -> None\n
Handle a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.FileHandler","title":"FileHandler","text":" Bases: BaseHandler
Handler for writing log records to a file.
Parameters:
Name Type Description Defaultfile_name
str
Name of the file to write log records to.
requiredlevel
Level
Logging level for the handler.
NOTSET
formatter
Formatter
Formatter instance to format the log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.FileHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.LoggingAdapterHandler","title":"LoggingAdapterHandler","text":" Bases: Handler
Adapter handler to integrate with the standard logging module.
Parameters:
Name Type Description Defaulthandler
BaseHandler
Custom handler to delegate log records to.
required"},{"location":"api/#tinylogging.LoggingAdapterHandler.emit","title":"emit","text":"emit(record: LogRecord) -> None\n
Emit a log record using the custom handler.
Parameters:
Name Type Description Defaultrecord
LogRecord
The log record to be emitted.
required"},{"location":"api/#tinylogging.StreamHandler","title":"StreamHandler","text":" Bases: BaseHandler
Handler for streaming log records to a stream.
Parameters:
Name Type Description Defaultformatter
Formatter
Formatter instance to format the log records.
Formatter()
level
Level
Logging level for the handler.
NOTSET
stream
Optional[TextIO]
Stream to write log records to.
None
"},{"location":"api/#tinylogging.StreamHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the stream.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.TelegramHandler","title":"TelegramHandler","text":" Bases: BaseHandler
Handler for sending log records to a Telegram chat.
Parameters:
Name Type Description Defaulttoken
str
Telegram bot token.
requiredchat_id
int | str
Chat ID to send messages to.
requiredignore_errors
bool
Whether to ignore errors when sending messages.
False
message_thread_id
Optional[int]
ID of the message thread.
None
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.TelegramHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.aio","title":"aio","text":""},{"location":"api/#tinylogging.aio.AsyncFileHandler","title":"AsyncFileHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for writing log records to a file.
"},{"location":"api/#tinylogging.aio.AsyncFileHandler.__init__","title":"__init__","text":"__init__(file_name: str, level: Level = NOTSET, formatter: Formatter = Formatter(colorize=False)) -> None\n
Initializes the AsyncFileHandler.
Parameters:
Name Type Description Defaultfile_name
str
The name of the file to write log records to.
requiredlevel
Level
The logging level threshold for this handler.
NOTSET
formatter
Formatter
The formatter instance to format log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.aio.AsyncFileHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.aio.AsyncTelegramHandler","title":"AsyncTelegramHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for sending log records to a Telegram chat.
"},{"location":"api/#tinylogging.aio.AsyncTelegramHandler.__init__","title":"__init__","text":"__init__(token: str, chat_id: int | str, message_thread_id: Optional[int] = None, ignore_errors: bool = False, **kwargs: Any) -> None\n
Initializes the AsyncTelegramHandler.
Parameters:
Name Type Description Defaulttoken
str
The Telegram bot token.
requiredchat_id
int | str
The chat ID to send log records to.
requiredmessage_thread_id
Optional[int]
The message thread ID (optional).
None
ignore_errors
bool
Whether to ignore errors during sending.
False
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.aio.AsyncTelegramHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.aio.BaseAsyncHandler","title":"BaseAsyncHandler","text":" Bases: ABC
Base class for all async handlers.
"},{"location":"api/#tinylogging.aio.BaseAsyncHandler.__init__","title":"__init__","text":"__init__(formatter: Formatter = Formatter(), level: Level = NOTSET) -> None\n
Initializes the BaseAsyncHandler.
Parameters:
Name Type Description Defaultformatter
Formatter
The formatter instance to format log records.
Formatter()
level
Level
The logging level threshold for this handler.
NOTSET
"},{"location":"api/#tinylogging.aio.BaseAsyncHandler.emit","title":"emit abstractmethod
async
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
requiredRaises:
Type DescriptionNotImplementedError
This method should be overridden by subclasses.
"},{"location":"api/#tinylogging.aio.BaseAsyncHandler.handle","title":"handleasync
","text":"handle(record: Record) -> None\n
Handle a log record if it meets the logging level threshold.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.aio.AsyncLogger","title":"AsyncLogger","text":""},{"location":"api/#tinylogging.aio.AsyncLogger.__init__","title":"__init__","text":"__init__(name: str, level: Level = NOTSET, formatter: Formatter = Formatter(), handlers: set[BaseAsyncHandler] = set()) -> None\n
Initializes an asynchronous logger.
Parameters:
Name Type Description Defaultname
str
The name of the logger.
requiredlevel
Level
The logging level. Defaults to Level.NOTSET.
NOTSET
formatter
Formatter
The formatter for log messages. Defaults to Formatter().
Formatter()
handlers
set[BaseAsyncHandler]
A set of handlers for the logger. Defaults to an empty set.
set()
"},{"location":"api/#tinylogging.aio.AsyncLogger.log","title":"log async
","text":"log(message: str, level: Level) -> None\n
Logs a message at the specified level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
requiredlevel
Level
The level at which to log the message.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.trace","title":"traceasync
","text":"trace(message: str) -> None\n
Logs a message with TRACE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.debug","title":"debugasync
","text":"debug(message: str) -> None\n
Logs a message with DEBUG level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.info","title":"infoasync
","text":"info(message: str) -> None\n
Logs a message with INFO level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.notice","title":"noticeasync
","text":"notice(message: str) -> None\n
Logs a message with NOTICE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.warning","title":"warningasync
","text":"warning(message: str) -> None\n
Logs a message with WARNING level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.error","title":"errorasync
","text":"error(message: str) -> None\n
Logs a message with ERROR level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.critical","title":"criticalasync
","text":"critical(message: str) -> None\n
Logs a message with CRITICAL level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.enable","title":"enable","text":"enable() -> None\n
Enables the logger.
"},{"location":"api/#tinylogging.aio.AsyncLogger.disable","title":"disable","text":"disable() -> None\n
Disables the logger.
"},{"location":"api/#tinylogging.aio.handlers","title":"handlers","text":""},{"location":"api/#tinylogging.aio.handlers.BaseAsyncHandler","title":"BaseAsyncHandler","text":" Bases: ABC
Base class for all async handlers.
"},{"location":"api/#tinylogging.aio.handlers.BaseAsyncHandler.__init__","title":"__init__","text":"__init__(formatter: Formatter = Formatter(), level: Level = NOTSET) -> None\n
Initializes the BaseAsyncHandler.
Parameters:
Name Type Description Defaultformatter
Formatter
The formatter instance to format log records.
Formatter()
level
Level
The logging level threshold for this handler.
NOTSET
"},{"location":"api/#tinylogging.aio.handlers.BaseAsyncHandler.emit","title":"emit abstractmethod
async
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
requiredRaises:
Type DescriptionNotImplementedError
This method should be overridden by subclasses.
"},{"location":"api/#tinylogging.aio.handlers.BaseAsyncHandler.handle","title":"handleasync
","text":"handle(record: Record) -> None\n
Handle a log record if it meets the logging level threshold.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.aio.handlers.AsyncStreamHandler","title":"AsyncStreamHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for streaming log records.
"},{"location":"api/#tinylogging.aio.handlers.AsyncStreamHandler.__init__","title":"__init__","text":"__init__(formatter: Formatter = Formatter(), level: Level = NOTSET, stream: Optional[AsyncFile[str]] = None) -> None\n
Initializes the AsyncStreamHandler.
Parameters:
Name Type Description Defaultformatter
Formatter
The formatter instance to format log records.
Formatter()
level
Level
The logging level threshold for this handler.
NOTSET
stream
Optional[AsyncFile[str]]
The stream to write log records to.
None
"},{"location":"api/#tinylogging.aio.handlers.AsyncStreamHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the stream.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.aio.handlers.AsyncFileHandler","title":"AsyncFileHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for writing log records to a file.
"},{"location":"api/#tinylogging.aio.handlers.AsyncFileHandler.__init__","title":"__init__","text":"__init__(file_name: str, level: Level = NOTSET, formatter: Formatter = Formatter(colorize=False)) -> None\n
Initializes the AsyncFileHandler.
Parameters:
Name Type Description Defaultfile_name
str
The name of the file to write log records to.
requiredlevel
Level
The logging level threshold for this handler.
NOTSET
formatter
Formatter
The formatter instance to format log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.aio.handlers.AsyncFileHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.aio.handlers.AsyncTelegramHandler","title":"AsyncTelegramHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for sending log records to a Telegram chat.
"},{"location":"api/#tinylogging.aio.handlers.AsyncTelegramHandler.__init__","title":"__init__","text":"__init__(token: str, chat_id: int | str, message_thread_id: Optional[int] = None, ignore_errors: bool = False, **kwargs: Any) -> None\n
Initializes the AsyncTelegramHandler.
Parameters:
Name Type Description Defaulttoken
str
The Telegram bot token.
requiredchat_id
int | str
The chat ID to send log records to.
requiredmessage_thread_id
Optional[int]
The message thread ID (optional).
None
ignore_errors
bool
Whether to ignore errors during sending.
False
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.aio.handlers.AsyncTelegramHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.formatter","title":"formatter","text":""},{"location":"api/#tinylogging.formatter.Formatter","title":"Formatter","text":""},{"location":"api/#tinylogging.formatter.Formatter.__init__","title":"__init__","text":"__init__(time_format: str = '[%H:%M:%S]', template: str = '{time} | {level} | {relpath}:{line} | {message}', colorize: bool = True) -> None\n
Initializes the Formatter instance.
Parameters:
Name Type Description Defaulttime_format
str
The format for the timestamp in log messages.
'[%H:%M:%S]'
template
str
The template for formatting log messages.
'{time} | {level} | {relpath}:{line} | {message}'
colorize
bool
Whether to colorize the log messages.
True
"},{"location":"api/#tinylogging.formatter.Formatter.format","title":"format","text":"format(record: Record) -> str\n
Formats a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to format.
requiredReturns:
Name Type Descriptionstr
str
The formatted log message.
"},{"location":"api/#tinylogging.helpers","title":"helpers","text":""},{"location":"api/#tinylogging.helpers.TelegramFormatter","title":"TelegramFormatter","text":" Bases: Formatter
__init__(time_format: str = '%H:%M:%S')\n
Initializes the TelegramFormatter with a specific time format and template.
Parameters:
Name Type Description Defaulttime_format
str
The format string for formatting the time. Defaults to \"%H:%M:%S\".
'%H:%M:%S'
"},{"location":"api/#tinylogging.helpers.TelegramFormatter.format","title":"format","text":"format(record: Record) -> str\n
Formats a log record into a string suitable for Telegram.
Parameters:
Name Type Description Defaultrecord
Record
The log record to format.
requiredReturns:
Name Type Descriptionstr
str
The formatted log record as a string.
"},{"location":"api/#tinylogging.level","title":"level","text":""},{"location":"api/#tinylogging.level.Level","title":"Level","text":" Bases: IntEnum
Enumeration for logging levels.
Attributes:
Name Type DescriptionNOTSET
No level set.
TRACE
Trace level for detailed debugging.
DEBUG
Debug level for general debugging.
INFO
Informational messages.
NOTICE
Notice level for normal but significant conditions.
WARNING
Warning level for potentially harmful situations.
ERROR
Error level for error events.
CRITICAL
Critical level for severe error events.
"},{"location":"api/#tinylogging.record","title":"record","text":""},{"location":"api/#tinylogging.record.Record","title":"Recorddataclass
","text":"Represents a log record.
Attributes:
Name Type Descriptionmessage
str
The log message.
level
Level
The log level.
name
str
The name of the logger.
time
datetime
The time the log record was created.
filename
str
The name of the file where the log record was created.
line
int
The line number in the file where the log record was created.
function
str
The function name where the log record was created.
"},{"location":"api/#tinylogging.record.Record.basename","title":"basenameproperty
","text":"basename: str\n
Gets the base name of the file where the log record was created.
Returns:
Name Type Descriptionstr
str
The base name of the file.
"},{"location":"api/#tinylogging.record.Record.relpath","title":"relpathproperty
","text":"relpath: str\n
Gets the relative path of the file where the log record was created.
Returns:
Name Type Descriptionstr
str
The relative path of the file.
"},{"location":"api/#tinylogging.record.Record.__post_init__","title":"__post_init__","text":"__post_init__() -> None\n
Initializes additional attributes after the dataclass is created.
Raises:
Type DescriptionRuntimeError
If the stack frame cannot be retrieved.
"},{"location":"api/#tinylogging.record.Record.to_dict","title":"to_dict","text":"to_dict() -> dict[str, Any]\n
Converts the log record to a dictionary.
Returns:
Name Type Descriptiondict
dict[str, Any]
A dictionary representation of the log record.
"},{"location":"api/#tinylogging.sync","title":"sync","text":""},{"location":"api/#tinylogging.sync.Formatter","title":"Formatter","text":""},{"location":"api/#tinylogging.sync.Formatter.__init__","title":"__init__","text":"__init__(time_format: str = '[%H:%M:%S]', template: str = '{time} | {level} | {relpath}:{line} | {message}', colorize: bool = True) -> None\n
Initializes the Formatter instance.
Parameters:
Name Type Description Defaulttime_format
str
The format for the timestamp in log messages.
'[%H:%M:%S]'
template
str
The template for formatting log messages.
'{time} | {level} | {relpath}:{line} | {message}'
colorize
bool
Whether to colorize the log messages.
True
"},{"location":"api/#tinylogging.sync.Formatter.format","title":"format","text":"format(record: Record) -> str\n
Formats a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to format.
requiredReturns:
Name Type Descriptionstr
str
The formatted log message.
"},{"location":"api/#tinylogging.sync.BaseHandler","title":"BaseHandler","text":" Bases: ABC
Abstract base class for all handlers.
Parameters:
Name Type Description Defaultformatter
Formatter
Formatter instance to format the log records.
Formatter()
level
Level
Logging level for the handler.
NOTSET
"},{"location":"api/#tinylogging.sync.BaseHandler.emit","title":"emit abstractmethod
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.BaseHandler.handle","title":"handle","text":"handle(record: Record) -> None\n
Handle a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.sync.FileHandler","title":"FileHandler","text":" Bases: BaseHandler
Handler for writing log records to a file.
Parameters:
Name Type Description Defaultfile_name
str
Name of the file to write log records to.
requiredlevel
Level
Logging level for the handler.
NOTSET
formatter
Formatter
Formatter instance to format the log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.sync.FileHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.LoggingAdapterHandler","title":"LoggingAdapterHandler","text":" Bases: Handler
Adapter handler to integrate with the standard logging module.
Parameters:
Name Type Description Defaulthandler
BaseHandler
Custom handler to delegate log records to.
required"},{"location":"api/#tinylogging.sync.LoggingAdapterHandler.emit","title":"emit","text":"emit(record: LogRecord) -> None\n
Emit a log record using the custom handler.
Parameters:
Name Type Description Defaultrecord
LogRecord
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.TelegramHandler","title":"TelegramHandler","text":" Bases: BaseHandler
Handler for sending log records to a Telegram chat.
Parameters:
Name Type Description Defaulttoken
str
Telegram bot token.
requiredchat_id
int | str
Chat ID to send messages to.
requiredignore_errors
bool
Whether to ignore errors when sending messages.
False
message_thread_id
Optional[int]
ID of the message thread.
None
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.sync.TelegramHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.Logger","title":"Logger","text":""},{"location":"api/#tinylogging.sync.Logger.__init__","title":"__init__","text":"__init__(name: str, level: Level = NOTSET, formatter: Formatter = Formatter(), handlers: set[BaseHandler] = set()) -> None\n
Initializes a new Logger instance.
Parameters:
Name Type Description Defaultname
str
The name of the logger.
requiredlevel
Level
The logging level. Defaults to Level.NOTSET.
NOTSET
formatter
Formatter
The formatter for log messages. Defaults to Formatter().
Formatter()
handlers
set[BaseHandler]
A set of handlers for the logger. Defaults to an empty set.
set()
"},{"location":"api/#tinylogging.sync.Logger.log","title":"log","text":"log(message: str, level: Level) -> None\n
Logs a message with the specified logging level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
requiredlevel
Level
The logging level for the message.
required"},{"location":"api/#tinylogging.sync.Logger.trace","title":"trace","text":"trace(message: str) -> None\n
Logs a message with TRACE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.debug","title":"debug","text":"debug(message: str) -> None\n
Logs a message with DEBUG level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.info","title":"info","text":"info(message: str) -> None\n
Logs a message with INFO level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.notice","title":"notice","text":"notice(message: str) -> None\n
Logs a message with NOTICE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.warning","title":"warning","text":"warning(message: str) -> None\n
Logs a message with WARNING level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.error","title":"error","text":"error(message: str) -> None\n
Logs a message with ERROR level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.critical","title":"critical","text":"critical(message: str) -> None\n
Logs a message with CRITICAL level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.enable","title":"enable","text":"enable() -> None\n
Enables the logger.
"},{"location":"api/#tinylogging.sync.Logger.disable","title":"disable","text":"disable() -> None\n
Disables the logger.
"},{"location":"api/#tinylogging.sync.handlers","title":"handlers","text":""},{"location":"api/#tinylogging.sync.handlers.BaseHandler","title":"BaseHandler","text":" Bases: ABC
Abstract base class for all handlers.
Parameters:
Name Type Description Defaultformatter
Formatter
Formatter instance to format the log records.
Formatter()
level
Level
Logging level for the handler.
NOTSET
"},{"location":"api/#tinylogging.sync.handlers.BaseHandler.emit","title":"emit abstractmethod
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.handlers.BaseHandler.handle","title":"handle","text":"handle(record: Record) -> None\n
Handle a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.sync.handlers.StreamHandler","title":"StreamHandler","text":" Bases: BaseHandler
Handler for streaming log records to a stream.
Parameters:
Name Type Description Defaultformatter
Formatter
Formatter instance to format the log records.
Formatter()
level
Level
Logging level for the handler.
NOTSET
stream
Optional[TextIO]
Stream to write log records to.
None
"},{"location":"api/#tinylogging.sync.handlers.StreamHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the stream.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.handlers.FileHandler","title":"FileHandler","text":" Bases: BaseHandler
Handler for writing log records to a file.
Parameters:
Name Type Description Defaultfile_name
str
Name of the file to write log records to.
requiredlevel
Level
Logging level for the handler.
NOTSET
formatter
Formatter
Formatter instance to format the log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.sync.handlers.FileHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.handlers.LoggingAdapterHandler","title":"LoggingAdapterHandler","text":" Bases: Handler
Adapter handler to integrate with the standard logging module.
Parameters:
Name Type Description Defaulthandler
BaseHandler
Custom handler to delegate log records to.
required"},{"location":"api/#tinylogging.sync.handlers.LoggingAdapterHandler.emit","title":"emit","text":"emit(record: LogRecord) -> None\n
Emit a log record using the custom handler.
Parameters:
Name Type Description Defaultrecord
LogRecord
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.handlers.TelegramHandler","title":"TelegramHandler","text":" Bases: BaseHandler
Handler for sending log records to a Telegram chat.
Parameters:
Name Type Description Defaulttoken
str
Telegram bot token.
requiredchat_id
int | str
Chat ID to send messages to.
requiredignore_errors
bool
Whether to ignore errors when sending messages.
False
message_thread_id
Optional[int]
ID of the message thread.
None
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.sync.handlers.TelegramHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"changelog/","title":"Changelog","text":"All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
"},{"location":"changelog/#unreleased","title":"[Unreleased]","text":""},{"location":"changelog/#500-2025-01-25","title":"[5.0.0] - 2025-01-25","text":""},{"location":"changelog/#added","title":"Added","text":"to_dict
for the Record
classCOLOR_MAP
from tinylogging/__init__.py
message_thread_id
for handlers AsyncTelegramHandler
and TelegramHandler
Formatter
TelegramFormatter
from [%H:%M:%S]
to %H:%M:%S
AsyncTelegramHandler
, TelegramHandler
) (#4)TelegramFormatter
for processing and formatting messages sent to Telegramhttpx
for working with the Telegram APILoggingAdapterHandler
where the attributes filename
, function
, and line
were not set for the Record
objectRecord
class: filename
, line
, basename
, relpath
, function
template
) for the Formatter
class, the relative path to the file and line are displayedanyio
LoggingAdapterHandler
: an adapter for integration with the logging
module allowing the use of custom handlers (BaseHandler
, StreamHandler
, etc.) with standard Python loggerspip install tinylogging\n
"},{"location":"#usage","title":"Usage","text":""},{"location":"#new-logger","title":"New logger","text":"from tinylogging import Logger, Level\n\nlogger = Logger(name=\"my_logger\", level=Level.DEBUG)\n
"},{"location":"#logging-messages","title":"Logging messages","text":"logger.info(\"This is an info message.\")\nlogger.error(\"This is an error message.\")\nlogger.debug(\"This is a debug message.\")\n
"},{"location":"#logging-to-a-file","title":"Logging to a file","text":"from tinylogging import FileHandler\n\nfile_handler = FileHandler(file_name=\"app.log\", level=Level.WARNING)\nlogger.handlers.add(file_handler)\n\nlogger.warning(\"This warning will be logged to both console and file.\")\n
"},{"location":"#custom-formatting","title":"Custom formatting","text":"from tinylogging import Formatter\n\nformatter = Formatter(template=\"{time} - {name} - {level} - {message}\", colorize=False)\nlogger = Logger(name=\"custom_logger\", formatter=formatter)\nlogger.info(\"This log message uses a custom format.\")\n
"},{"location":"#disabling-logging","title":"Disabling logging","text":"logger.disable()\nlogger.info(\"This message will not be logged.\")\nlogger.enable()\n
"},{"location":"#async-support","title":"Async support","text":"import asyncio\nfrom tinylogging import AsyncLogger, AsyncFileHandler\n\n\nasync def main():\n logger = AsyncLogger(name=\"async_logger\")\n\n file_handler = AsyncFileHandler(file_name=\"app.log\")\n logger.handlers.add(file_handler)\n\n await logger.info(\"This is an info message.\")\n await logger.error(\"This is an error message.\")\n await logger.debug(\"This is a debug message.\")\n\n\nif __name__ == \"__main__\":\n asyncio.run(main)\n
"},{"location":"#license","title":"License","text":"This project is licensed under the MIT License.
"},{"location":"api/","title":"API reference","text":""},{"location":"api/#tinylogging","title":"tinylogging","text":""},{"location":"api/#tinylogging.AsyncLogger","title":"AsyncLogger","text":""},{"location":"api/#tinylogging.AsyncLogger.__init__","title":"__init__","text":"__init__(name: str, level: Level = NOTSET, formatter: Formatter = Formatter(), handlers: set[BaseAsyncHandler] = set()) -> None\n
Initializes an asynchronous logger.
Parameters:
Name Type Description Defaultname
str
The name of the logger.
requiredlevel
Level
The logging level. Defaults to Level.NOTSET.
NOTSET
formatter
Formatter
The formatter for log messages. Defaults to Formatter().
Formatter()
handlers
set[BaseAsyncHandler]
A set of handlers for the logger. Defaults to an empty set.
set()
"},{"location":"api/#tinylogging.AsyncLogger.log","title":"log async
","text":"log(message: str, level: Level) -> None\n
Logs a message at the specified level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
requiredlevel
Level
The level at which to log the message.
required"},{"location":"api/#tinylogging.AsyncLogger.trace","title":"traceasync
","text":"trace(message: str) -> None\n
Logs a message with TRACE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.debug","title":"debugasync
","text":"debug(message: str) -> None\n
Logs a message with DEBUG level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.info","title":"infoasync
","text":"info(message: str) -> None\n
Logs a message with INFO level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.notice","title":"noticeasync
","text":"notice(message: str) -> None\n
Logs a message with NOTICE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.warning","title":"warningasync
","text":"warning(message: str) -> None\n
Logs a message with WARNING level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.error","title":"errorasync
","text":"error(message: str) -> None\n
Logs a message with ERROR level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.critical","title":"criticalasync
","text":"critical(message: str) -> None\n
Logs a message with CRITICAL level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.AsyncLogger.enable","title":"enable","text":"enable() -> None\n
Enables the logger.
"},{"location":"api/#tinylogging.AsyncLogger.disable","title":"disable","text":"disable() -> None\n
Disables the logger.
"},{"location":"api/#tinylogging.AsyncFileHandler","title":"AsyncFileHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for writing log records to a file.
"},{"location":"api/#tinylogging.AsyncFileHandler.__init__","title":"__init__","text":"__init__(file_name: str, level: Level = NOTSET, formatter: Formatter = Formatter(colorize=False)) -> None\n
Initializes the AsyncFileHandler.
Parameters:
Name Type Description Defaultfile_name
str
The name of the file to write log records to.
requiredlevel
Level
The logging level threshold for this handler.
NOTSET
formatter
Formatter
The formatter instance to format log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.AsyncFileHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.AsyncStreamHandler","title":"AsyncStreamHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for streaming log records.
"},{"location":"api/#tinylogging.AsyncStreamHandler.__init__","title":"__init__","text":"__init__(formatter: Formatter = Formatter(), level: Level = NOTSET, stream: Optional[AsyncFile[str]] = None) -> None\n
Initializes the AsyncStreamHandler.
Parameters:
Name Type Description Defaultformatter
Formatter
The formatter instance to format log records.
Formatter()
level
Level
The logging level threshold for this handler.
NOTSET
stream
Optional[AsyncFile[str]]
The stream to write log records to.
None
"},{"location":"api/#tinylogging.AsyncStreamHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the stream.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.AsyncTelegramHandler","title":"AsyncTelegramHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for sending log records to a Telegram chat.
"},{"location":"api/#tinylogging.AsyncTelegramHandler.__init__","title":"__init__","text":"__init__(token: str, chat_id: int | str, message_thread_id: Optional[int] = None, ignore_errors: bool = False, **kwargs: Any) -> None\n
Initializes the AsyncTelegramHandler.
Parameters:
Name Type Description Defaulttoken
str
The Telegram bot token.
requiredchat_id
int | str
The chat ID to send log records to.
requiredmessage_thread_id
Optional[int]
The message thread ID (optional).
None
ignore_errors
bool
Whether to ignore errors during sending.
False
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.AsyncTelegramHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.BaseAsyncHandler","title":"BaseAsyncHandler","text":" Bases: ABC
Base class for all async handlers.
"},{"location":"api/#tinylogging.BaseAsyncHandler.__init__","title":"__init__","text":"__init__(formatter: Formatter = Formatter(), level: Level = NOTSET) -> None\n
Initializes the BaseAsyncHandler.
Parameters:
Name Type Description Defaultformatter
Formatter
The formatter instance to format log records.
Formatter()
level
Level
The logging level threshold for this handler.
NOTSET
"},{"location":"api/#tinylogging.BaseAsyncHandler.emit","title":"emit abstractmethod
async
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
requiredRaises:
Type DescriptionNotImplementedError
This method should be overridden by subclasses.
"},{"location":"api/#tinylogging.BaseAsyncHandler.handle","title":"handleasync
","text":"handle(record: Record) -> None\n
Handle a log record if it meets the logging level threshold.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.Formatter","title":"Formatter","text":""},{"location":"api/#tinylogging.Formatter.__init__","title":"__init__","text":"__init__(time_format: str = '[%H:%M:%S]', template: str = '{time} | {level} | {relpath}:{line} | {message}', colorize: bool = True) -> None\n
Initializes the Formatter instance.
Parameters:
Name Type Description Defaulttime_format
str
The format for the timestamp in log messages.
'[%H:%M:%S]'
template
str
The template for formatting log messages.
'{time} | {level} | {relpath}:{line} | {message}'
colorize
bool
Whether to colorize the log messages.
True
"},{"location":"api/#tinylogging.Formatter.format","title":"format","text":"format(record: Record) -> str\n
Formats a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to format.
requiredReturns:
Name Type Descriptionstr
str
The formatted log message.
"},{"location":"api/#tinylogging.Level","title":"Level","text":" Bases: IntEnum
Enumeration for logging levels.
Attributes:
Name Type DescriptionNOTSET
No level set.
TRACE
Trace level for detailed debugging.
DEBUG
Debug level for general debugging.
INFO
Informational messages.
NOTICE
Notice level for normal but significant conditions.
WARNING
Warning level for potentially harmful situations.
ERROR
Error level for error events.
CRITICAL
Critical level for severe error events.
"},{"location":"api/#tinylogging.Record","title":"Recorddataclass
","text":"Represents a log record.
Attributes:
Name Type Descriptionmessage
str
The log message.
level
Level
The log level.
name
str
The name of the logger.
time
datetime
The time the log record was created.
filename
str
The name of the file where the log record was created.
line
int
The line number in the file where the log record was created.
function
str
The function name where the log record was created.
"},{"location":"api/#tinylogging.Record.basename","title":"basenameproperty
","text":"basename: str\n
Gets the base name of the file where the log record was created.
Returns:
Name Type Descriptionstr
str
The base name of the file.
"},{"location":"api/#tinylogging.Record.relpath","title":"relpathproperty
","text":"relpath: str\n
Gets the relative path of the file where the log record was created.
Returns:
Name Type Descriptionstr
str
The relative path of the file.
"},{"location":"api/#tinylogging.Record.__post_init__","title":"__post_init__","text":"__post_init__() -> None\n
Initializes additional attributes after the dataclass is created.
Raises:
Type DescriptionRuntimeError
If the stack frame cannot be retrieved.
"},{"location":"api/#tinylogging.Record.to_dict","title":"to_dict","text":"to_dict() -> dict[str, Any]\n
Converts the log record to a dictionary.
Returns:
Name Type Descriptiondict
dict[str, Any]
A dictionary representation of the log record.
"},{"location":"api/#tinylogging.Logger","title":"Logger","text":""},{"location":"api/#tinylogging.Logger.__init__","title":"__init__","text":"__init__(name: str, level: Level = NOTSET, formatter: Formatter = Formatter(), handlers: set[BaseHandler] = set()) -> None\n
Initializes a new Logger instance.
Parameters:
Name Type Description Defaultname
str
The name of the logger.
requiredlevel
Level
The logging level. Defaults to Level.NOTSET.
NOTSET
formatter
Formatter
The formatter for log messages. Defaults to Formatter().
Formatter()
handlers
set[BaseHandler]
A set of handlers for the logger. Defaults to an empty set.
set()
"},{"location":"api/#tinylogging.Logger.log","title":"log","text":"log(message: str, level: Level) -> None\n
Logs a message with the specified logging level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
requiredlevel
Level
The logging level for the message.
required"},{"location":"api/#tinylogging.Logger.trace","title":"trace","text":"trace(message: str) -> None\n
Logs a message with TRACE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.debug","title":"debug","text":"debug(message: str) -> None\n
Logs a message with DEBUG level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.info","title":"info","text":"info(message: str) -> None\n
Logs a message with INFO level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.notice","title":"notice","text":"notice(message: str) -> None\n
Logs a message with NOTICE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.warning","title":"warning","text":"warning(message: str) -> None\n
Logs a message with WARNING level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.error","title":"error","text":"error(message: str) -> None\n
Logs a message with ERROR level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.critical","title":"critical","text":"critical(message: str) -> None\n
Logs a message with CRITICAL level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.Logger.enable","title":"enable","text":"enable() -> None\n
Enables the logger.
"},{"location":"api/#tinylogging.Logger.disable","title":"disable","text":"disable() -> None\n
Disables the logger.
"},{"location":"api/#tinylogging.BaseHandler","title":"BaseHandler","text":" Bases: ABC
Abstract base class for all handlers.
Parameters:
Name Type Description Defaultformatter
Formatter
Formatter instance to format the log records.
Formatter()
level
Level
Logging level for the handler.
NOTSET
"},{"location":"api/#tinylogging.BaseHandler.emit","title":"emit abstractmethod
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.BaseHandler.handle","title":"handle","text":"handle(record: Record) -> None\n
Handle a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.FileHandler","title":"FileHandler","text":" Bases: BaseHandler
Handler for writing log records to a file.
Parameters:
Name Type Description Defaultfile_name
str
Name of the file to write log records to.
requiredlevel
Level
Logging level for the handler.
NOTSET
formatter
Formatter
Formatter instance to format the log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.FileHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.LoggingAdapterHandler","title":"LoggingAdapterHandler","text":" Bases: Handler
Adapter handler to integrate with the standard logging module.
Parameters:
Name Type Description Defaulthandler
BaseHandler
Custom handler to delegate log records to.
required"},{"location":"api/#tinylogging.LoggingAdapterHandler.emit","title":"emit","text":"emit(record: LogRecord) -> None\n
Emit a log record using the custom handler.
Parameters:
Name Type Description Defaultrecord
LogRecord
The log record to be emitted.
required"},{"location":"api/#tinylogging.StreamHandler","title":"StreamHandler","text":" Bases: BaseHandler
Handler for streaming log records to a stream.
Parameters:
Name Type Description Defaultformatter
Formatter
Formatter instance to format the log records.
Formatter()
level
Level
Logging level for the handler.
NOTSET
stream
Optional[TextIO]
Stream to write log records to.
None
"},{"location":"api/#tinylogging.StreamHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the stream.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.TelegramHandler","title":"TelegramHandler","text":" Bases: BaseHandler
Handler for sending log records to a Telegram chat.
Parameters:
Name Type Description Defaulttoken
str
Telegram bot token.
requiredchat_id
int | str
Chat ID to send messages to.
requiredignore_errors
bool
Whether to ignore errors when sending messages.
False
message_thread_id
Optional[int]
ID of the message thread.
None
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.TelegramHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.aio","title":"aio","text":""},{"location":"api/#tinylogging.aio.AsyncFileHandler","title":"AsyncFileHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for writing log records to a file.
"},{"location":"api/#tinylogging.aio.AsyncFileHandler.__init__","title":"__init__","text":"__init__(file_name: str, level: Level = NOTSET, formatter: Formatter = Formatter(colorize=False)) -> None\n
Initializes the AsyncFileHandler.
Parameters:
Name Type Description Defaultfile_name
str
The name of the file to write log records to.
requiredlevel
Level
The logging level threshold for this handler.
NOTSET
formatter
Formatter
The formatter instance to format log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.aio.AsyncFileHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.aio.AsyncTelegramHandler","title":"AsyncTelegramHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for sending log records to a Telegram chat.
"},{"location":"api/#tinylogging.aio.AsyncTelegramHandler.__init__","title":"__init__","text":"__init__(token: str, chat_id: int | str, message_thread_id: Optional[int] = None, ignore_errors: bool = False, **kwargs: Any) -> None\n
Initializes the AsyncTelegramHandler.
Parameters:
Name Type Description Defaulttoken
str
The Telegram bot token.
requiredchat_id
int | str
The chat ID to send log records to.
requiredmessage_thread_id
Optional[int]
The message thread ID (optional).
None
ignore_errors
bool
Whether to ignore errors during sending.
False
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.aio.AsyncTelegramHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.aio.BaseAsyncHandler","title":"BaseAsyncHandler","text":" Bases: ABC
Base class for all async handlers.
"},{"location":"api/#tinylogging.aio.BaseAsyncHandler.__init__","title":"__init__","text":"__init__(formatter: Formatter = Formatter(), level: Level = NOTSET) -> None\n
Initializes the BaseAsyncHandler.
Parameters:
Name Type Description Defaultformatter
Formatter
The formatter instance to format log records.
Formatter()
level
Level
The logging level threshold for this handler.
NOTSET
"},{"location":"api/#tinylogging.aio.BaseAsyncHandler.emit","title":"emit abstractmethod
async
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
requiredRaises:
Type DescriptionNotImplementedError
This method should be overridden by subclasses.
"},{"location":"api/#tinylogging.aio.BaseAsyncHandler.handle","title":"handleasync
","text":"handle(record: Record) -> None\n
Handle a log record if it meets the logging level threshold.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.aio.AsyncLogger","title":"AsyncLogger","text":""},{"location":"api/#tinylogging.aio.AsyncLogger.__init__","title":"__init__","text":"__init__(name: str, level: Level = NOTSET, formatter: Formatter = Formatter(), handlers: set[BaseAsyncHandler] = set()) -> None\n
Initializes an asynchronous logger.
Parameters:
Name Type Description Defaultname
str
The name of the logger.
requiredlevel
Level
The logging level. Defaults to Level.NOTSET.
NOTSET
formatter
Formatter
The formatter for log messages. Defaults to Formatter().
Formatter()
handlers
set[BaseAsyncHandler]
A set of handlers for the logger. Defaults to an empty set.
set()
"},{"location":"api/#tinylogging.aio.AsyncLogger.log","title":"log async
","text":"log(message: str, level: Level) -> None\n
Logs a message at the specified level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
requiredlevel
Level
The level at which to log the message.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.trace","title":"traceasync
","text":"trace(message: str) -> None\n
Logs a message with TRACE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.debug","title":"debugasync
","text":"debug(message: str) -> None\n
Logs a message with DEBUG level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.info","title":"infoasync
","text":"info(message: str) -> None\n
Logs a message with INFO level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.notice","title":"noticeasync
","text":"notice(message: str) -> None\n
Logs a message with NOTICE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.warning","title":"warningasync
","text":"warning(message: str) -> None\n
Logs a message with WARNING level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.error","title":"errorasync
","text":"error(message: str) -> None\n
Logs a message with ERROR level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.critical","title":"criticalasync
","text":"critical(message: str) -> None\n
Logs a message with CRITICAL level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.aio.AsyncLogger.enable","title":"enable","text":"enable() -> None\n
Enables the logger.
"},{"location":"api/#tinylogging.aio.AsyncLogger.disable","title":"disable","text":"disable() -> None\n
Disables the logger.
"},{"location":"api/#tinylogging.aio.handlers","title":"handlers","text":""},{"location":"api/#tinylogging.aio.handlers.BaseAsyncHandler","title":"BaseAsyncHandler","text":" Bases: ABC
Base class for all async handlers.
"},{"location":"api/#tinylogging.aio.handlers.BaseAsyncHandler.__init__","title":"__init__","text":"__init__(formatter: Formatter = Formatter(), level: Level = NOTSET) -> None\n
Initializes the BaseAsyncHandler.
Parameters:
Name Type Description Defaultformatter
Formatter
The formatter instance to format log records.
Formatter()
level
Level
The logging level threshold for this handler.
NOTSET
"},{"location":"api/#tinylogging.aio.handlers.BaseAsyncHandler.emit","title":"emit abstractmethod
async
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
requiredRaises:
Type DescriptionNotImplementedError
This method should be overridden by subclasses.
"},{"location":"api/#tinylogging.aio.handlers.BaseAsyncHandler.handle","title":"handleasync
","text":"handle(record: Record) -> None\n
Handle a log record if it meets the logging level threshold.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.aio.handlers.AsyncStreamHandler","title":"AsyncStreamHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for streaming log records.
"},{"location":"api/#tinylogging.aio.handlers.AsyncStreamHandler.__init__","title":"__init__","text":"__init__(formatter: Formatter = Formatter(), level: Level = NOTSET, stream: Optional[AsyncFile[str]] = None) -> None\n
Initializes the AsyncStreamHandler.
Parameters:
Name Type Description Defaultformatter
Formatter
The formatter instance to format log records.
Formatter()
level
Level
The logging level threshold for this handler.
NOTSET
stream
Optional[AsyncFile[str]]
The stream to write log records to.
None
"},{"location":"api/#tinylogging.aio.handlers.AsyncStreamHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the stream.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.aio.handlers.AsyncFileHandler","title":"AsyncFileHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for writing log records to a file.
"},{"location":"api/#tinylogging.aio.handlers.AsyncFileHandler.__init__","title":"__init__","text":"__init__(file_name: str, level: Level = NOTSET, formatter: Formatter = Formatter(colorize=False)) -> None\n
Initializes the AsyncFileHandler.
Parameters:
Name Type Description Defaultfile_name
str
The name of the file to write log records to.
requiredlevel
Level
The logging level threshold for this handler.
NOTSET
formatter
Formatter
The formatter instance to format log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.aio.handlers.AsyncFileHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.aio.handlers.AsyncTelegramHandler","title":"AsyncTelegramHandler","text":" Bases: BaseAsyncHandler
Asynchronous handler for sending log records to a Telegram chat.
"},{"location":"api/#tinylogging.aio.handlers.AsyncTelegramHandler.__init__","title":"__init__","text":"__init__(token: str, chat_id: int | str, message_thread_id: Optional[int] = None, ignore_errors: bool = False, **kwargs: Any) -> None\n
Initializes the AsyncTelegramHandler.
Parameters:
Name Type Description Defaulttoken
str
The Telegram bot token.
requiredchat_id
int | str
The chat ID to send log records to.
requiredmessage_thread_id
Optional[int]
The message thread ID (optional).
None
ignore_errors
bool
Whether to ignore errors during sending.
False
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.aio.handlers.AsyncTelegramHandler.emit","title":"emit async
","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.formatter","title":"formatter","text":""},{"location":"api/#tinylogging.formatter.Formatter","title":"Formatter","text":""},{"location":"api/#tinylogging.formatter.Formatter.__init__","title":"__init__","text":"__init__(time_format: str = '[%H:%M:%S]', template: str = '{time} | {level} | {relpath}:{line} | {message}', colorize: bool = True) -> None\n
Initializes the Formatter instance.
Parameters:
Name Type Description Defaulttime_format
str
The format for the timestamp in log messages.
'[%H:%M:%S]'
template
str
The template for formatting log messages.
'{time} | {level} | {relpath}:{line} | {message}'
colorize
bool
Whether to colorize the log messages.
True
"},{"location":"api/#tinylogging.formatter.Formatter.format","title":"format","text":"format(record: Record) -> str\n
Formats a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to format.
requiredReturns:
Name Type Descriptionstr
str
The formatted log message.
"},{"location":"api/#tinylogging.helpers","title":"helpers","text":""},{"location":"api/#tinylogging.helpers.TelegramFormatter","title":"TelegramFormatter","text":" Bases: Formatter
__init__(time_format: str = '%H:%M:%S')\n
Initializes the TelegramFormatter with a specific time format and template.
Parameters:
Name Type Description Defaulttime_format
str
The format string for formatting the time. Defaults to \"%H:%M:%S\".
'%H:%M:%S'
"},{"location":"api/#tinylogging.helpers.TelegramFormatter.format","title":"format","text":"format(record: Record) -> str\n
Formats a log record into a string suitable for Telegram.
Parameters:
Name Type Description Defaultrecord
Record
The log record to format.
requiredReturns:
Name Type Descriptionstr
str
The formatted log record as a string.
"},{"location":"api/#tinylogging.level","title":"level","text":""},{"location":"api/#tinylogging.level.Level","title":"Level","text":" Bases: IntEnum
Enumeration for logging levels.
Attributes:
Name Type DescriptionNOTSET
No level set.
TRACE
Trace level for detailed debugging.
DEBUG
Debug level for general debugging.
INFO
Informational messages.
NOTICE
Notice level for normal but significant conditions.
WARNING
Warning level for potentially harmful situations.
ERROR
Error level for error events.
CRITICAL
Critical level for severe error events.
"},{"location":"api/#tinylogging.record","title":"record","text":""},{"location":"api/#tinylogging.record.Record","title":"Recorddataclass
","text":"Represents a log record.
Attributes:
Name Type Descriptionmessage
str
The log message.
level
Level
The log level.
name
str
The name of the logger.
time
datetime
The time the log record was created.
filename
str
The name of the file where the log record was created.
line
int
The line number in the file where the log record was created.
function
str
The function name where the log record was created.
"},{"location":"api/#tinylogging.record.Record.basename","title":"basenameproperty
","text":"basename: str\n
Gets the base name of the file where the log record was created.
Returns:
Name Type Descriptionstr
str
The base name of the file.
"},{"location":"api/#tinylogging.record.Record.relpath","title":"relpathproperty
","text":"relpath: str\n
Gets the relative path of the file where the log record was created.
Returns:
Name Type Descriptionstr
str
The relative path of the file.
"},{"location":"api/#tinylogging.record.Record.__post_init__","title":"__post_init__","text":"__post_init__() -> None\n
Initializes additional attributes after the dataclass is created.
Raises:
Type DescriptionRuntimeError
If the stack frame cannot be retrieved.
"},{"location":"api/#tinylogging.record.Record.to_dict","title":"to_dict","text":"to_dict() -> dict[str, Any]\n
Converts the log record to a dictionary.
Returns:
Name Type Descriptiondict
dict[str, Any]
A dictionary representation of the log record.
"},{"location":"api/#tinylogging.sync","title":"sync","text":""},{"location":"api/#tinylogging.sync.Formatter","title":"Formatter","text":""},{"location":"api/#tinylogging.sync.Formatter.__init__","title":"__init__","text":"__init__(time_format: str = '[%H:%M:%S]', template: str = '{time} | {level} | {relpath}:{line} | {message}', colorize: bool = True) -> None\n
Initializes the Formatter instance.
Parameters:
Name Type Description Defaulttime_format
str
The format for the timestamp in log messages.
'[%H:%M:%S]'
template
str
The template for formatting log messages.
'{time} | {level} | {relpath}:{line} | {message}'
colorize
bool
Whether to colorize the log messages.
True
"},{"location":"api/#tinylogging.sync.Formatter.format","title":"format","text":"format(record: Record) -> str\n
Formats a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to format.
requiredReturns:
Name Type Descriptionstr
str
The formatted log message.
"},{"location":"api/#tinylogging.sync.BaseHandler","title":"BaseHandler","text":" Bases: ABC
Abstract base class for all handlers.
Parameters:
Name Type Description Defaultformatter
Formatter
Formatter instance to format the log records.
Formatter()
level
Level
Logging level for the handler.
NOTSET
"},{"location":"api/#tinylogging.sync.BaseHandler.emit","title":"emit abstractmethod
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.BaseHandler.handle","title":"handle","text":"handle(record: Record) -> None\n
Handle a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.sync.FileHandler","title":"FileHandler","text":" Bases: BaseHandler
Handler for writing log records to a file.
Parameters:
Name Type Description Defaultfile_name
str
Name of the file to write log records to.
requiredlevel
Level
Logging level for the handler.
NOTSET
formatter
Formatter
Formatter instance to format the log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.sync.FileHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.LoggingAdapterHandler","title":"LoggingAdapterHandler","text":" Bases: Handler
Adapter handler to integrate with the standard logging module.
Parameters:
Name Type Description Defaulthandler
BaseHandler
Custom handler to delegate log records to.
required"},{"location":"api/#tinylogging.sync.LoggingAdapterHandler.emit","title":"emit","text":"emit(record: LogRecord) -> None\n
Emit a log record using the custom handler.
Parameters:
Name Type Description Defaultrecord
LogRecord
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.TelegramHandler","title":"TelegramHandler","text":" Bases: BaseHandler
Handler for sending log records to a Telegram chat.
Parameters:
Name Type Description Defaulttoken
str
Telegram bot token.
requiredchat_id
int | str
Chat ID to send messages to.
requiredignore_errors
bool
Whether to ignore errors when sending messages.
False
message_thread_id
Optional[int]
ID of the message thread.
None
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.sync.TelegramHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.Logger","title":"Logger","text":""},{"location":"api/#tinylogging.sync.Logger.__init__","title":"__init__","text":"__init__(name: str, level: Level = NOTSET, formatter: Formatter = Formatter(), handlers: set[BaseHandler] = set()) -> None\n
Initializes a new Logger instance.
Parameters:
Name Type Description Defaultname
str
The name of the logger.
requiredlevel
Level
The logging level. Defaults to Level.NOTSET.
NOTSET
formatter
Formatter
The formatter for log messages. Defaults to Formatter().
Formatter()
handlers
set[BaseHandler]
A set of handlers for the logger. Defaults to an empty set.
set()
"},{"location":"api/#tinylogging.sync.Logger.log","title":"log","text":"log(message: str, level: Level) -> None\n
Logs a message with the specified logging level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
requiredlevel
Level
The logging level for the message.
required"},{"location":"api/#tinylogging.sync.Logger.trace","title":"trace","text":"trace(message: str) -> None\n
Logs a message with TRACE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.debug","title":"debug","text":"debug(message: str) -> None\n
Logs a message with DEBUG level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.info","title":"info","text":"info(message: str) -> None\n
Logs a message with INFO level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.notice","title":"notice","text":"notice(message: str) -> None\n
Logs a message with NOTICE level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.warning","title":"warning","text":"warning(message: str) -> None\n
Logs a message with WARNING level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.error","title":"error","text":"error(message: str) -> None\n
Logs a message with ERROR level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.critical","title":"critical","text":"critical(message: str) -> None\n
Logs a message with CRITICAL level.
Parameters:
Name Type Description Defaultmessage
str
The message to log.
required"},{"location":"api/#tinylogging.sync.Logger.enable","title":"enable","text":"enable() -> None\n
Enables the logger.
"},{"location":"api/#tinylogging.sync.Logger.disable","title":"disable","text":"disable() -> None\n
Disables the logger.
"},{"location":"api/#tinylogging.sync.handlers","title":"handlers","text":""},{"location":"api/#tinylogging.sync.handlers.BaseHandler","title":"BaseHandler","text":" Bases: ABC
Abstract base class for all handlers.
Parameters:
Name Type Description Defaultformatter
Formatter
Formatter instance to format the log records.
Formatter()
level
Level
Logging level for the handler.
NOTSET
"},{"location":"api/#tinylogging.sync.handlers.BaseHandler.emit","title":"emit abstractmethod
","text":"emit(record: Record) -> None\n
Emit a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.handlers.BaseHandler.handle","title":"handle","text":"handle(record: Record) -> None\n
Handle a log record.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be handled.
required"},{"location":"api/#tinylogging.sync.handlers.StreamHandler","title":"StreamHandler","text":" Bases: BaseHandler
Handler for streaming log records to a stream.
Parameters:
Name Type Description Defaultformatter
Formatter
Formatter instance to format the log records.
Formatter()
level
Level
Logging level for the handler.
NOTSET
stream
Optional[TextIO]
Stream to write log records to.
None
"},{"location":"api/#tinylogging.sync.handlers.StreamHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the stream.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.handlers.FileHandler","title":"FileHandler","text":" Bases: BaseHandler
Handler for writing log records to a file.
Parameters:
Name Type Description Defaultfile_name
str
Name of the file to write log records to.
requiredlevel
Level
Logging level for the handler.
NOTSET
formatter
Formatter
Formatter instance to format the log records.
Formatter(colorize=False)
"},{"location":"api/#tinylogging.sync.handlers.FileHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the file.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.handlers.LoggingAdapterHandler","title":"LoggingAdapterHandler","text":" Bases: Handler
Adapter handler to integrate with the standard logging module.
Parameters:
Name Type Description Defaulthandler
BaseHandler
Custom handler to delegate log records to.
required"},{"location":"api/#tinylogging.sync.handlers.LoggingAdapterHandler.emit","title":"emit","text":"emit(record: LogRecord) -> None\n
Emit a log record using the custom handler.
Parameters:
Name Type Description Defaultrecord
LogRecord
The log record to be emitted.
required"},{"location":"api/#tinylogging.sync.handlers.TelegramHandler","title":"TelegramHandler","text":" Bases: BaseHandler
Handler for sending log records to a Telegram chat.
Parameters:
Name Type Description Defaulttoken
str
Telegram bot token.
requiredchat_id
int | str
Chat ID to send messages to.
requiredignore_errors
bool
Whether to ignore errors when sending messages.
False
message_thread_id
Optional[int]
ID of the message thread.
None
**kwargs
Any
Additional keyword arguments for the base handler.
{}
"},{"location":"api/#tinylogging.sync.handlers.TelegramHandler.emit","title":"emit","text":"emit(record: Record) -> None\n
Emit a log record to the Telegram chat.
Parameters:
Name Type Description Defaultrecord
Record
The log record to be emitted.
required"},{"location":"changelog/","title":"Changelog","text":"All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
"},{"location":"changelog/#unreleased","title":"[Unreleased]","text":""},{"location":"changelog/#changed","title":"Changed","text":"poetry
to version 2.0.0to_dict
for the Record
classCOLOR_MAP
from tinylogging/__init__.py
message_thread_id
for handlers AsyncTelegramHandler
and TelegramHandler
Formatter
TelegramFormatter
from [%H:%M:%S]
to %H:%M:%S
AsyncTelegramHandler
, TelegramHandler
) (#4)TelegramFormatter
for processing and formatting messages sent to Telegramhttpx
for working with the Telegram APILoggingAdapterHandler
where the attributes filename
, function
, and line
were not set for the Record
objectRecord
class: filename
, line
, basename
, relpath
, function
template
) for the Formatter
class, the relative path to the file and line are displayedanyio
LoggingAdapterHandler
: an adapter for integration with the logging
module allowing the use of custom handlers (BaseHandler
, StreamHandler
, etc.) with standard Python loggers