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 7c25f20
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 3 additions & 0 deletions examples/metricq_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ async def on_data(
@metricq_command(default_token="sink-py-dummy")
@metricq_metric_option(multiple=True)
def source(server: str, token: str, metric: list[Metric]) -> None:

while True:
logger.exception("Test")
# Initialize the DummySink class with a list of metrics given on the
# command line.
sink = DummySink(metrics=metric, token=token, url=server)
Expand Down
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",
]
10 changes: 5 additions & 5 deletions metricq/cli/wrapper.py
Original file line number Diff line number Diff line change
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,12 @@ 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, required: bool = False, default: Optional[str] = None, **kwargs
) -> Callable[[FC], FC]:
def get_syslog_handler(address: str) -> SysLogHandler:
if ":" in address:
Expand All @@ -139,7 +138,8 @@ def get_syslog_handler(address: str) -> SysLogHandler:
else:
return SysLogHandler(address=address)

def decorator(func): # type: ignore
def decorator(func):# type: ignore
@__metricq_command(*args, **kwargs)
@click.option(
"--syslog",
default=default,
Expand Down

0 comments on commit 7c25f20

Please sign in to comment.