Skip to content

Commit

Permalink
feat: renamed the syslog to metricq_command to avoid multiple wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
devmaxde committed Nov 5, 2024
1 parent 50c8f6e commit fcec397
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/metricq_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def main(server: str, token: str) -> None:


if __name__ == "__main__":
main()
main() # type: ignore
2 changes: 1 addition & 1 deletion examples/metricq_get_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ def get_history(


if __name__ == "__main__":
get_history()
get_history() # type: ignore
2 changes: 1 addition & 1 deletion examples/metricq_get_history_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ def get_history(server: str, token: str, metric: str) -> None:


if __name__ == "__main__":
get_history()
get_history() # type: ignore
2 changes: 1 addition & 1 deletion examples/metricq_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ def get_history(server: str, token: str, metric: str) -> None:


if __name__ == "__main__":
get_history()
get_history() # type: ignore
2 changes: 1 addition & 1 deletion examples/metricq_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ def source(server: str, token: str, metric: list[Metric]) -> None:


if __name__ == "__main__":
source()
source() # type: ignore
2 changes: 1 addition & 1 deletion examples/metricq_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ def source(server: str, token: str) -> None:


if __name__ == "__main__":
source()
source() # type: ignore
2 changes: 1 addition & 1 deletion examples/metricq_synchronous_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ def synchronous_source(server: str, token: str) -> None:


if __name__ == "__main__":
synchronous_source()
synchronous_source() # type: ignore
2 changes: 0 additions & 2 deletions metricq/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
metricq_command,
metricq_metric_option,
metricq_server_option,
metricq_syslog,
metricq_token_option,
)

Expand All @@ -24,6 +23,5 @@
"metricq_command",
"metricq_metric_option",
"metricq_server_option",
"metricq_syslog",
"metricq_token_option",
]
17 changes: 10 additions & 7 deletions metricq/cli/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
from functools import wraps
from logging.handlers import SysLogHandler
from typing import Callable, Optional, cast
from typing import Any, Callable, Optional, cast

import click
import click_log # type: ignore
Expand Down Expand Up @@ -74,7 +74,7 @@ def get_metric_command_logger() -> logging.Logger:
return logger


def metricq_command(
def __metricq_command(
default_token: str, client_version: str | None = None
) -> Callable[[FC], click.Command]:
logger = get_metric_command_logger()
Expand Down Expand Up @@ -124,13 +124,15 @@ def format(self, record: logging.LogRecord) -> str:
# Format the header as "<PRI> TIMESTAMP HOSTNAME PROGRAM[PID]: MESSAGE"
# <PRI> is already beeing set by the SysLogHanlder, we only need to add the rest
syslog_header = f"{timestamp} {hostname} {program}[{pid}]: "

message = super().format(record)
return syslog_header + message


def metricq_syslog(
required: bool = True, default: Optional[str] = None
def metricq_command(
*args: Any,
syslog_required: bool = False,
syslog_default: Optional[str] = None,
**kwargs: Any,
) -> Callable[[FC], FC]:
def get_syslog_handler(address: str) -> SysLogHandler:
if ":" in address:
Expand All @@ -140,14 +142,15 @@ def get_syslog_handler(address: str) -> SysLogHandler:
return SysLogHandler(address=address)

def decorator(func): # type: ignore
@__metricq_command(*args, **kwargs)
@click.option(
"--syslog",
default=default,
default=syslog_default,
help="Setting this param will enable Syslog for the current program.",
)
@wraps(func)
def wrapper(*args, syslog, **kwargs): # type: ignore
if required and syslog is None:
if syslog_required and syslog is None:
raise ValueError("Input syslog is missing")
if syslog is not None:
logger = get_logger()
Expand Down

0 comments on commit fcec397

Please sign in to comment.