77from click import Context , option
88from dotenv import find_dotenv , load_dotenv
99
10- from .. import get_logger
10+ from ..logging import get_logger , FORMAT
1111from .params import MetricParam , TemplateStringParam
1212from .syslog import SyslogFormatter , get_syslog_handler
1313
2424FC = TypeVar ("FC" , bound = Union [Callable [..., Any ], click .Command ])
2525
2626
27- def metricq_syslog_option () -> Callable [[FC ], FC ]:
27+ def syslog_option () -> Callable [[FC ], FC ]:
2828 """
2929 Exposes the -\\ -syslog option as a click param.
3030
3131 The program will try read the 'token' from the click params.
3232 if the token is not set, the default value of 'metricq.program' will be used.
33- That's why the @metricq_syslog_option should be the 2nd decorator in the chain.
33+ That's why the @syslog_option should be the 2nd decorator in the chain.
3434
35- It is recommended to use the :py:func:`~metricq.cli.decorator.metricq_command ` decorator instead of using this
35+ It is recommended to use the :py:func:`~metricq.cli.decorator.command ` decorator instead of using this
3636 function directly.
3737 """
3838
@@ -50,20 +50,21 @@ def enable_syslog(ctx: Context, param: Any | None, value: Optional[str]) -> None
5050
5151 return option (
5252 "--syslog" ,
53- help = "Enable syslog logging by specifying the a Unix socket or host:port for the logger. If --syslog is set "
54- "but no value is specified, the default of localhost:514 will be used." ,
53+ help = "Enable syslog logging by specifying a Unix socket or a host:port"
54+ " combination for the logger. If --syslog is set but no value is "
55+ "specified, the default of localhost:514 will be used." ,
5556 callback = enable_syslog ,
5657 expose_value = False ,
5758 is_flag = False ,
5859 flag_value = "" ,
5960 )
6061
6162
62- def metricq_server_option () -> Callable [[FC ], FC ]:
63+ def server_option () -> Callable [[FC ], FC ]:
6364 """
6465 Allows the User to provide a -\\ -server option. This option has no input validation and therefore can be any string.
6566
66- It is recommended to use the :py:func:`~metricq.cli.decorator.metricq_command ` decorator instead
67+ It is recommended to use the :py:func:`~metricq.cli.decorator.command ` decorator instead
6768 of using this function directly.
6869
6970 """
@@ -76,12 +77,12 @@ def metricq_server_option() -> Callable[[FC], FC]:
7677 )
7778
7879
79- def metricq_token_option (default : str ) -> Callable [[FC ], FC ]:
80+ def token_option (default : str ) -> Callable [[FC ], FC ]:
8081 """
8182 Allows the User to provide a -\\ -metric option. The input must follow the specification provided
8283 `here <https://github.com/metricq/metricq/wiki/Metrics#selecting-good-metric-names>`_.
8384
84- It is recommended to use the :py:func:`~metricq.cli.decorator.metricq_command ` decorator instead of using this
85+ It is recommended to use the :py:func:`~metricq.cli.decorator.command ` decorator instead of using this
8586 function directly.
8687 """
8788 return option (
@@ -94,7 +95,7 @@ def metricq_token_option(default: str) -> Callable[[FC], FC]:
9495 )
9596
9697
97- def metricq_metric_option (
98+ def metric_option (
9899 default : Optional [str ] = None , multiple : bool = False , required : bool = False
99100) -> Callable [[FC ], FC ]:
100101 """
@@ -111,8 +112,8 @@ def metricq_metric_option(
111112
112113 **Example**::
113114
114- @metricq_command (default_token="example.program")
115- @metricq_metricq_option (required=true, default="example.metric")
115+ @command (default_token="example.program")
116+ @metric_option (required=true, default="example.metric")
116117 def metric_example(
117118 server: str, token: str, metric: str
118119 ) -> None:
@@ -123,8 +124,8 @@ def metric_example(
123124 # Run the sink. This call will block until the connection is closed.
124125 sink.run()
125126
126- @metricq_command (default_token="example.program")
127- @metricq_metricq_option (required=true, multiple=True) # <-- multiple is set
127+ @command (default_token="example.program")
128+ @metric_option (required=true, multiple=True) # <-- multiple is set
128129 def multi_metric_example(
129130 server: str, token: str, metric: List[str]
130131 ) -> None:
@@ -150,15 +151,17 @@ def multi_metric_example(
150151 )
151152
152153
153- def get_metric_command_logger () -> logging .Logger :
154+ def _get_metric_command_logger () -> logging .Logger :
154155 logger = get_logger ()
155156 logger .setLevel (logging .WARNING )
156157 click_log .basic_config (logger )
157158
159+ logger .handlers [0 ].formatter = logging .Formatter (fmt = FORMAT )
160+
158161 return logger
159162
160163
161- def metricq_command (
164+ def command (
162165 default_token : str , client_version : str | None = None
163166) -> Callable [[FC ], click .Command ]:
164167 """Standardized wrapper for click commands
@@ -170,7 +173,7 @@ def metricq_command(
170173 Returns:
171174 Callable[[FC], click.Command]: click command
172175
173- The :py:func:`~metricq.cli.wrapper.metricq_command ` is the first parameter of any given click/cli command. The main purpose is to provide the most used parameters.
176+ The :py:func:`~metricq.cli.wrapper.command ` is the first parameter of any given click/cli command. The main purpose is to provide the most used parameters.
174177 These parameters are 'server' and 'token'.
175178
176179 - -\\ -server:
@@ -198,7 +201,7 @@ def metricq_command(
198201
199202 **Example**::
200203
201- @metricq_command (default_token="source-py-dummy")
204+ @command (default_token="source-py-dummy")
202205 def dummy(
203206 server: str, token: str
204207 ) -> None:
@@ -210,15 +213,15 @@ def dummy(
210213 dummy()
211214
212215 """
213- logger = get_metric_command_logger ()
216+ logger = _get_metric_command_logger ()
214217
215218 log_decorator = cast (
216219 Callable [[FC ], FC ], click_log .simple_verbosity_option (logger , default = "warning" )
217220 )
218221 context_settings = {"auto_envvar_prefix" : "METRICQ" }
219222 epilog = (
220- "All options can be passed as environment variables prefixed with 'METRICQ_'. "
221- "I.e. , 'METRICQ_SERVER=amqps://...'.\n "
223+ "All options can be passed as environment variables prefixed with 'METRICQ_', "
224+ "for example , 'METRICQ_SERVER=amqps://...'.\n "
222225 "\n "
223226 "You can also create a '.metricq' file in the current or home directory that "
224227 "contains environment variable settings in the same format.\n "
@@ -230,9 +233,9 @@ def dummy(
230233 def decorator (func : FC ) -> click .Command :
231234 return click .version_option (version = client_version )(
232235 log_decorator (
233- metricq_token_option (default_token )(
234- metricq_server_option ()(
235- metricq_syslog_option ()(
236+ token_option (default_token )(
237+ server_option ()(
238+ syslog_option ()(
236239 click .command (
237240 context_settings = context_settings , epilog = epilog
238241 )(func )
0 commit comments