Skip to content

Commit

Permalink
Added --log-level option
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Mar 14, 2021
1 parent b79c880 commit 844c7a8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ v0.2.0 (in development)
-----------------------
- Require the `port` field of `SMTPSender` to be non-negative
- Mark `Sender` as `runtime_checkable` and export it
- Gave the `outgoing` command `--section` and `--no-section` options
- Gave the `outgoing` command `--section`, `--no-section`, and `--log-level`
options
- Added logging to built-in sender classes

v0.1.0 (2021-03-06)
Expand Down
4 changes: 2 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ v0.2.0 (in development)
-----------------------
- Require the ``port`` field of ``SMTPSender`` to be non-negative
- Mark `Sender` as ``runtime_checkable`` and export it
- Gave the :command:`outgoing` command ``--section`` and ``--no-section``
options
- Gave the :command:`outgoing` command ``--section``, ``--no-section``, and
``--log-level`` options
- Added logging to built-in sender classes

v0.1.0 (2021-03-06)
Expand Down
10 changes: 10 additions & 0 deletions docs/command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ Options
Specify a :ref:`configuration file <configfile>` to use instead of the
default configuration file

.. option:: -l <level>, --log-level <level>

.. versionadded:: 0.2.0

Set the `logging level`_ to the given value; default: ``INFO``. The level
can be given as a case-insensitive level name or as a numeric value.

.. _logging level: https://docs.python.org/3/library/logging.html
#logging-levels

.. option:: -s <key>, --section <key>

.. versionadded:: 0.2.0
Expand Down
15 changes: 8 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ package_dir =
include_package_data = True
python_requires = ~=3.6
install_requires =
appdirs ~= 1.4
click >= 7.0
entrypoints ~= 0.3
keyring >= 21.7
morecontext ~= 0.4
pydantic ~= 1.7
python-dotenv ~= 0.11
appdirs ~= 1.4
click >= 7.0
click-loglevel ~= 0.2
entrypoints ~= 0.3
keyring >= 21.7
morecontext ~= 0.4
pydantic ~= 1.7
python-dotenv ~= 0.11
toml
typing_extensions; python_version < "3.8"

Expand Down
20 changes: 19 additions & 1 deletion src/outgoing/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from email import message_from_binary_file, policy
from email.message import EmailMessage
import logging
from typing import Any, IO, List, Optional
import click
from click_loglevel import LogLevel
from . import (
DEFAULT_CONFIG_SECTION,
__version__,
Expand All @@ -28,6 +30,13 @@
help="Specify the outgoing configuration file to use",
show_default=True,
)
@click.option(
"-l",
"--log-level",
type=LogLevel(),
default=logging.INFO,
help="Set logging level [default: INFO]",
)
@click.option(
"-s",
"--section",
Expand All @@ -46,13 +55,22 @@
@click.argument("message", type=click.File("rb"), nargs=-1)
@click.pass_context
def main(
ctx: click.Context, message: List[IO[bytes]], config: Optional[str], section: Any
ctx: click.Context,
message: List[IO[bytes]],
config: Optional[str],
section: Any,
log_level: int,
) -> None:
"""
Common interface for different e-mail methods.
Visit <https://github.com/jwodder/outgoing> for more information.
"""
logging.basicConfig(
format="%(asctime)s [%(levelname)-8s] %(name)s %(message)s",
datefmt="%H:%M:%S",
level=log_level,
)
sectname: Optional[str]
if section is NO_SECTION:
sectname = None
Expand Down

0 comments on commit 844c7a8

Please sign in to comment.