Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HamletSargsyan committed Oct 5, 2024
1 parent 201a4b8 commit a262e4a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.*_cache

src/test.*

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## [2.1.0] - 2024-10-05

### Added

- `LoggingAdapterHandler`: an adapter for integration with the `logging` module, allowing the use of custom handlers (`BaseHandler`, `StreamHandler`, etc.) with Python's standard loggers.

## [2.0.0] - 2024-10-04

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tinylogging"
version = "2.0.0"
version = "2.1.0"
description = ""
authors = ["Hamlet <[email protected]>"]
license = "MIT"
Expand Down
16 changes: 16 additions & 0 deletions src/tinylogging/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import sys

from datetime import datetime
Expand Down Expand Up @@ -84,6 +85,7 @@ def handle(self, record: Record):
if record.level >= self.level:
self.emit(record)


class StreamHandler(BaseHandler):
def __init__(
self,
Expand Down Expand Up @@ -117,6 +119,20 @@ def emit(self, record: Record):
f.flush()


class LoggingAdapterHandler(logging.Handler):
def __init__(
self,
handler: BaseHandler,
):
super().__init__()
self.custom_handler = handler

def emit(self, record: logging.LogRecord):
level = Level[record.levelname] # cspell: disable-line
custom_record = Record(message=record.msg, level=level, name=record.name)
self.custom_handler.handle(custom_record)


class Logger:
def __init__(
self,
Expand Down

0 comments on commit a262e4a

Please sign in to comment.