Skip to content

Commit

Permalink
feat(logging): add date field when adding log
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Mar 4, 2024
1 parent 6a3a4d8 commit f3aa982
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/diceutils/logging.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from diceutils.exceptions import TooManyLoggersError
from datetime import datetime
from pathlib import Path
from typing import Dict, List, Any, Literal, Tuple, Union
from typing import Dict, List, Any, Literal, Optional, Tuple, Union

import sqlite3

Expand Down Expand Up @@ -203,6 +203,7 @@ def add(
user_role: Literal["KP", "PL", "OB", "DICER"] = "OB",
card_name: str = "User",
data: List[Any] = [],
date: Optional[Union[str, datetime]] = None,
message_sequence: str = "",
) -> None:
id = str(id)
Expand All @@ -217,14 +218,18 @@ def add(
raise ValueError(f"Unknown user role '{user_role}'.")
if not message_sequence or not isinstance(message_sequence, str):
raise ValueError("Message sequence string is require.")
if date is None:
date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
elif isinstance(date, datetime):
date = date.strftime("%Y-%m-%d %H:%M:%S")

self.log_manager.add(
session_id,
id,
user_id=user_id,
user_role=user_role,
card_name=card_name,
date=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
date=date,
data=str(data),
message_sequence=message_sequence,
)
Expand Down

0 comments on commit f3aa982

Please sign in to comment.