Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HamletSargsyan committed Jan 25, 2025
1 parent 6063bf8 commit 2555635
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Method `to_dict` for the `Record` class
- Documentation for project (#6)
- Typings for project

## [4.2.0] - 2025-01-17

### Added
Expand Down
4 changes: 3 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ tasks:
lint:
cmds:
- ruff check --respect-gitignore src
- mypy src
# - pyright src

format:
ignore_error: true
cmd: ruff format --respect-gitignore src

fix:
cmd: ruff check --respect-gitignore --fix src

dev-install:
cmds:
- pip install --upgrade ruff pyright pre-commit
- pip install --upgrade ruff pyright pre-commit mypy

dev-setup:
deps:
Expand Down
4 changes: 2 additions & 2 deletions src/tinylogging/aio/handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from abc import ABC, abstractmethod
from typing import Optional
from typing import Optional, Any

import httpx
from anyio import AsyncFile, open_file
Expand Down Expand Up @@ -141,7 +141,7 @@ def __init__(
chat_id: int | str,
message_thread_id: Optional[int] = None,
ignore_errors: bool = False,
**kwargs,
**kwargs: Any,
) -> None:
"""
Initializes the AsyncTelegramHandler.
Expand Down
Empty file added src/tinylogging/py.typed
Empty file.
24 changes: 18 additions & 6 deletions src/tinylogging/record.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import inspect
import os
from dataclasses import dataclass, field
from dataclasses import dataclass, field, asdict
from datetime import datetime
from typing import Any

from tinylogging.level import Level

Expand Down Expand Up @@ -54,16 +55,16 @@ def __post_init__(self) -> None:
frame = inspect.stack()[depth]

depth = self._get_stack_index()
frame = inspect.currentframe()
frame = inspect.currentframe() # type: ignore
for _ in range(depth):
frame = frame.f_back
frame = frame.f_back # type: ignore

if not frame:
raise RuntimeError("Failed to get stack frame")

self.filename = frame.f_code.co_filename
self.line = frame.f_lineno
self.function = frame.f_code.co_name
self.filename = frame.f_code.co_filename # type: ignore
self.line = frame.f_lineno # type: ignore
self.function = frame.f_code.co_name # type: ignore

def _get_stack_index(self) -> int:
"""Gets the index of the stack frame for the log record.
Expand All @@ -79,3 +80,14 @@ def _get_stack_index(self) -> int:
current_frame = current_frame.f_back
index += 1
return 1

def to_dict(self) -> dict[str, Any]:
"""Converts the log record to a dictionary.
Returns:
dict: A dictionary representation of the log record.
"""
dict_ = asdict(self)
dict_["basename"] = self.basename
dict_["relpath"] = self.relpath
return dict_
4 changes: 2 additions & 2 deletions src/tinylogging/sync/handlers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import sys
from abc import ABC, abstractmethod
from typing import TextIO, Optional
from typing import TextIO, Optional, Any

import httpx

Expand Down Expand Up @@ -163,7 +163,7 @@ def __init__(
chat_id: int | str,
ignore_errors: bool = False,
message_thread_id: Optional[int] = None,
**kwargs,
**kwargs: Any,
) -> None:
super().__init__(**kwargs)
self.token = token
Expand Down

0 comments on commit 2555635

Please sign in to comment.