Skip to content

Commit

Permalink
refactor: allow turn json as option in sm
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Jan 30, 2024
1 parent e079f71 commit 82d18c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "typelog"
version = "0.2.7"
version = "0.2.8"
description = "Static typed structured logging"
readme = "README.md"
authors = [{ name = "dd84ai", email = "dark.dreamflyer@gmail.com" }]
Expand Down
22 changes: 16 additions & 6 deletions typelog/logcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class StructuredMessage:
def __init__(
self,
message: str,
turn_json: Optional[bool],
*args: LogType,
turn_json: Optional[bool] = None,
) -> None:
self._message = message
self._turn_json = turn_json
Expand Down Expand Up @@ -56,27 +56,37 @@ def __init__(self, name: str, turn_json: Optional[bool]):

def debug(self, message: str, *args: LogType) -> None:
self._logger.debug(
StructuredMessage(message, self._turn_json, *(args + self._with_fields))
StructuredMessage(
message, *(args + self._with_fields), turn_json=self._turn_json
)
)

def info(self, message: str, *args: LogType) -> None:
self._logger.info(
StructuredMessage(message, self._turn_json, *(args + self._with_fields))
StructuredMessage(
message, *(args + self._with_fields), turn_json=self._turn_json
)
)

def warn(self, message: str, *args: LogType) -> None:
self._logger.warning(
StructuredMessage(message, self._turn_json, *(args + self._with_fields))
StructuredMessage(
message, *(args + self._with_fields), turn_json=self._turn_json
)
)

def error(self, message: str, *args: LogType) -> None:
self._logger.error(
StructuredMessage(message, self._turn_json, *(args + self._with_fields))
StructuredMessage(
message, *(args + self._with_fields), turn_json=self._turn_json
)
)

def fatal(self, message: str, *args: LogType) -> None:
self._logger.fatal(
StructuredMessage(message, self._turn_json, *(args + self._with_fields))
StructuredMessage(
message, *(args + self._with_fields), turn_json=self._turn_json
)
)

def with_fields(self, *args: LogType) -> "Typelog":
Expand Down

0 comments on commit 82d18c6

Please sign in to comment.