Skip to main content

logkit(tt)

This project is my personal lib with some logging helpers.

I use it in my other projects to make logging configuration simpler.

Installation

pip install logkittt

Public API

Check demo script (examples/demo.py) and corresponding log output (examples/demo.log)

get_logger(...)
get_logger(
    base_name: str,
    module_name: str,
    *,
    level: str = "DEBUG",
    propagate: bool = True,
) -> logging.LoggerAdapter

Create logger with a name representing current project. Calls from project subfolder will create a correct hierarchy of loggers.

from logkittt.core import get_logger
logger = get_logger("my_app", __name__)

Parameters:

  • base_name: str, prefix for logger name.
  • module_name: str (usually __name__, including "__main__"), defines module part of logger name.
  • level: str (for example "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"), sets logger level threshold.
  • propagate: bool, enables/disables propagation to parent loggers.
add_handlers(...)
add_handlers(
    logger: logging.LoggerAdapter,
    application: str,
    handlers: list,
) -> logging.LoggerAdapter

Attach configured handlers to logger and keep application context for records.

from logkittt.core import add_handlers
from logkittt.handlers import DefaultConsoleHandler
add_handlers(logger, __file__, [DefaultConsoleHandler()])

Parameters:

  • logger: logging.LoggerAdapter, logger instance created by get_logger call.
  • application: str (often __file__), used to set app_name in logger extra context.
  • handlers: list, every handler in list is attached to the logger.
catch_all_exceptions(...)
catch_all_exceptions(
    logger: logging.LoggerAdapter,
    *,
    reraise: bool = False,
) -> Callable

Wrap function execution with exception logging. Can optionally raise the original exception after logging.

from logkittt.core import catch_all_exceptions

@catch_all_exceptions(logger, reraise=False)
def main() -> None:
    ...

Parameters:

  • logger: logging.LoggerAdapter, logger instance created by get_logger call.
  • reraise: bool, if True, exception is raised again after logging.
log_run(...)
log_run(
    logger: logging.LoggerAdapter,
    fn: str,
    params: Mapping[str, Any],
) -> None

Log run context for current execution. That includes filename, git commit (if available), specified paramters. Usually called at the beginning of main, that allow to track when did the script started and input parameters.

from logkittt.core import log_run

def main(param1: str, param2: str):
    log_run(logger, __file__, locals())

Outputs:

2026-03-05 02:13:21 :: my_app :: INFO :: Run: examples/demo.py
2026-03-05 02:13:21 :: my_app :: INFO :: Current branch is: main
commit: 660c911bcecf7aa58bfeb7cc9abc463bde5e2768
2026-03-05 02:13:21 :: my_app :: INFO :: Params:
2026-03-05 02:13:21 :: my_app :: INFO ::   param1: test1
2026-03-05 02:13:21 :: my_app :: INFO ::   param2: test2

Parameters:

  • logger: logging.LoggerAdapter, logger instance created by get_logger call.
  • fn: str (often __file__), script filename.
  • params: Mapping[str, Any], values are logged as run parameters.
log_df(...)
log_df(
    logger: logging.LoggerAdapter,
    df: Any,
    title: str | None = None,
    v2s: Callable[[Any], str] | None = None,
    level: str = "INFO",
    col_size: int | None = None,
) -> None

Log DataFrame data in a readable table-like text form.

from logkittt.core import log_df
log_df(logger, df, v2s=lambda v: str(v))

Outputs:

2026-03-05 02:13:21 :: my_app :: INFO ::    nums str
2026-03-05 02:13:21 :: my_app :: INFO :: 0: 0    ttt
2026-03-05 02:13:21 :: my_app :: INFO :: 1: 1    ttt
2026-03-05 02:13:21 :: my_app :: INFO :: 2: 2    ttt
2026-03-05 02:13:21 :: my_app :: INFO :: 3: 3    ttt
2026-03-05 02:13:21 :: my_app :: INFO :: 4: 4    ttt

Parameters:

  • logger: logging.LoggerAdapter, logger instance created by get_logger call.
  • df: Any (expected pandas.DataFrame), source data to print.
  • title: str | None, optional header line before table.
  • v2s: Callable[[Any], str] | None, converts each cell value to string before alignment.
  • level: str (for example "INFO", "DEBUG", "WARNING", "ERROR", "CRITICAL"), selects logging level for DataFrame output.
  • col_size: int | None, minimum width per output column.
DefaultConsoleHandler(...)
DefaultConsoleHandler()

Create console handler with project default formatting.

from logkittt.handlers import DefaultConsoleHandler
handler = DefaultConsoleHandler()

Parameters:

  • None
DefaultFileHandler(...)
DefaultFileHandler(
    fn: str,
)

Create file handler with project default formatting.

from logkittt.handlers import DefaultFileHandler
handler = DefaultFileHandler("logs/demo.log")

Parameters:

  • fn: str, target log file path (parent directories are created if needed).
TelegramHandler(...)
TelegramHandler(
    token: str,
    username: str | list[str],
    prefix: str = "",
    notify_levels: list[str] = ["INFO", "ERROR", "CRITICAL", "WARNING"],
    only_level: str | None = None,
)

Create handler for sending log messages to Telegram.

from logkittt.web_handlers import TelegramHandler
handler = TelegramHandler("BOT_TOKEN", ["username"])

Parameters:

  • token: str, authenticates bot API requests.
  • username: str | list[str], selects Telegram users/chats for delivery.
  • prefix: str, prepends text to every sent message.
  • notify_levels: list[str], levels in this list are sent with active notifications.
  • only_level: str | None, None sends all levels; otherwise sends only matching level.

Release files for logkittt 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logkittt 0.1.1
File Size Uploaded
logkittt-0.1.1.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for logkittt 0.1.1
File Interpreter ABI Platform
logkittt-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / logkittt-0.1.1.tar.gz

Download URL logkittt-0.1.1.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5f05ace7445fb632028957537c88bcbd3d7d96572581318e861d271f1b273d04
BLAKE2b-256 checksum
How to use checksums
6f908c12ebd0ab41c02b28addd5f5edaa9542516d17add46961f8568c12f1b09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release files / logkittt-0.1.1-py3-none-any.whl

Download URL logkittt-0.1.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a728d692074311db108006bca240b2e073414af43e56da61bd7fec297b8f739
BLAKE2b-256 checksum
How to use checksums
79e59d4b8e787f1bed75165ddf4e0e7293b421cdb3efe84ff543089be725e6d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page