-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update logging and output functionality
- Loading branch information
Jean-Louis Fuchs
committed
Mar 13, 2024
1 parent
88ba5a1
commit 0f729bd
Showing
10 changed files
with
199 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Logging and output | ||
|
||
We use the logging facility for both debugging and output to the user. If you | ||
want to output a normal message (replacement of `print()`) use `lg.warn()`. The | ||
name might feel counter-intuitive, but I don't want to hack the logging-system | ||
and add new levels. `INFO` is basically reseved for successful commands. | ||
Unsuccessful commands are logged on `ERROR`. You can also hide unsuccessful command | ||
using `hide_error=True` in `run_command`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,45 @@ | ||
# Pyaptly | ||
|
||
Automates the creation and managment of aptly mirrors and snapshots based on yml | ||
Automates the creation and managment of aptly mirrors and snapshots based on toml | ||
input files. | ||
|
||
**Important**: Corrently under heavy development: | ||
|
||
- For for the old version [switch to the master branch](https://github.com/adfinis/pyaptly/tree/master) | ||
- Main branch builds contain [alpha packages](https://github.com/adfinis/pyaptly/actions/runs/8147002919), see Artifacts | ||
|
||
# Debugging | ||
|
||
The most interesting mode for users is not `--debug` but `--info` which show all commands executed. | ||
|
||
```bash | ||
# pyaptly legacy -- --info --config pyaptly/tests/repo.toml repo create | ||
Command call | ||
cmd: gpg --no-default-keyring --keyring trustedkeys.gpg --list-keys --with-colons -> 0 | ||
stdout: 'tru::1:1709575833:0:3:1:5 | ||
pub:-:255:22:2841988729C7F3FF:1701882080:::-:::scESC:::::ed25519:::0: | ||
fpr:::::::::6380C07FF6496016E01CF4522841988729C7F3FF: | ||
uid:-::::1701882080::5BBE9C7E7AA5EEE3538F66274125D69FA727FD1E::Pyaptly Test 01 <[email protected]>::::::::::0: | ||
sub:-:255:18:0A1CBEF26FE4F36E:1701882080::::::e:::::cv25519:: | ||
fpr:::::::::9EE64E40A5E3530D3E18A97C0A1CBEF26FE4F36E: | ||
pub:-:255:22:EC54D33E5B5EBE98:1701882297:::-:::scESC:::::ed25519:::0: | ||
fpr:::::::::660D45228AB6B59CCE48AFB3EC54D33E5B5EBE98: | ||
uid:-::::1701882297::F3EF71B78669C0FC259A4078151BDC5815A6015D::Pyaptly Test 02 <[email protected]>::::::::::0: | ||
sub:-:255:18:042FE0F5BB743B60:1701882297::::::e:::::cv25519:: | ||
fpr:::::::::AE58B62134E02AF8E5D55FF4042FE0F5BB743B60:' | ||
Command call | ||
cmd: aptly repo list -raw -> 0 | ||
stderr: 'Config file not found, creating default config at /root/.aptly.conf' | ||
Command call | ||
cmd: aptly mirror list -raw -> 0 | ||
Command call | ||
cmd: aptly snapshot list -raw -> 0 | ||
Command call | ||
cmd: aptly publish list -raw -> 0 | ||
Command call | ||
cmd: aptly repo -architectures=amd64,i386 -distribution=stable -component=main create centrify -> 0 | ||
stdout: 'Local repo [centrify] successfully added. | ||
You can run 'aptly repo add centrify ...' to add packages to repository.' | ||
``` | ||
|
||
Commands that fail are always displayed in red on a tty, but actually only happen if something is broken. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
from colorama import Fore, Style | ||
|
||
from . import util | ||
|
||
|
||
class CustomFormatter(logging.Formatter): | ||
debug = "%(levelname)s - %(filename)s:%(lineno)d: %(message)s" | ||
info_warn = "%(message)s" | ||
error_plus = "%(levelname)s: %(message)s" | ||
|
||
FORMATS_COLOR = { | ||
logging.DEBUG: Style.DIM + debug + Style.RESET_ALL, | ||
logging.INFO: Fore.YELLOW + info_warn + Style.RESET_ALL, | ||
logging.WARNING: info_warn, | ||
logging.ERROR: Fore.RED + error_plus + Style.RESET_ALL, | ||
logging.CRITICAL: Fore.MAGENTA + error_plus + Style.RESET_ALL, | ||
} | ||
|
||
FORMATS = { | ||
logging.DEBUG: debug, | ||
logging.INFO: info_warn, | ||
logging.WARNING: info_warn, | ||
logging.ERROR: error_plus, | ||
logging.CRITICAL: error_plus, | ||
} | ||
|
||
def format(self, record): | ||
if util.isatty(): | ||
formats = self.FORMATS_COLOR # pragma: no cover | ||
else: | ||
formats = self.FORMATS | ||
|
||
log_fmt = formats.get(record.levelno) | ||
formatter = logging.Formatter(log_fmt) | ||
return formatter.format(record) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters