Very verbose mode

In this new mode we print more information than in verbose mode.
Every matched policy is printed. That can be useful if one use a
config with many non final policies.
This commit is contained in:
feelancer21 2024-06-04 23:32:01 +02:00
parent 7f651450a9
commit 69d721fadd
No known key found for this signature in database
GPG key ID: 1F7071EE8449729C
4 changed files with 35 additions and 1 deletions

View file

@ -12,7 +12,7 @@ charge-lnd takes only a minimal set of parameters:
```
usage: charge-lnd [-h] [--lnddir LNDDIR] [--tlscert TLS_CERT_PATH] [--macaroon MACAROON_PATH] [--grpc GRPC]
[--circuitbreaker CIRCUITBREAKER] [--dry-run] [--check] [-v] -c CONFIG
[--circuitbreaker CIRCUITBREAKER] [--dry-run] [--check] [-v] [-vv] -c CONFIG
optional arguments:
-h, --help show this help message and exit
@ -28,6 +28,7 @@ optional arguments:
stdout
--check Do not perform actions, only check config file for valid syntax
-v, --verbose Be more verbose
-vv, --very-verbose Be very verbose, print every matched policy
-c CONFIG, --config CONFIG
path to config file
```

View file

@ -21,6 +21,9 @@ def main():
argument_parser = get_argument_parser()
arguments = argument_parser.parse_args()
if arguments.very_verbose:
arguments.verbose = True
if not os.path.exists(arguments.config):
debug("Config file not found")
return False
@ -183,6 +186,23 @@ def main():
s = '' + fmt.col_hi(chp.time_lock_delta)
print(" time_lock_delta: %s%s" % (fmt.col_hi(my_policy.time_lock_delta), s) )
if arguments.very_verbose:
fix = 40
print(fmt.col_hi(' ' + '-' * (fix + 34)))
for match in policy.log:
print(" %s%s" % (fmt.fix_str('policy_name', fix), fmt.col_hi(match.pop('policy_name'))))
if "strategy" in match:
print(" %s%s" % (fmt.fix_str('strategy', fix), fmt.col_hi(match.pop('strategy')[1])))
for k, v in match.items():
s = ''
if v[0]:
s = fmt.col_hi(v[0]) + ''
print(" %s%s%s" % (fmt.fix_str(k, fix), s, fmt.col_hi(v[1])))
print(fmt.col_hi(' ' + '-' * (fix + 30)))
if cb:
update_circuitbreaker(cb, lnd, arguments)
@ -280,6 +300,9 @@ def get_argument_parser():
parser.add_argument("-v", "--verbose",
action="store_true",
help="Be more verbose")
parser.add_argument("-vv", "--very-verbose",
action="store_true",
help="Be very verbose, print every matched policy")
parser.add_argument("-c", "--config",
required=True,
help="path to config file")

View file

@ -48,3 +48,6 @@ def col_err(s):
def col_val(s):
return str(colored(str(s),'yellow', attrs=['bold']))
def fix_str(s, l):
return str(s) + ' ' * (l - len(s))

View file

@ -44,11 +44,18 @@ class Policy:
self.strategy = None
self.name = None
self.config = {}
self.log = []
def apply(self, policy_name, policy_config):
config_ref = self.config.copy()
log = {}
self.log.append(log)
log['policy_name'] = policy_name
# mask over the collected config
for k,v in policy_config.items():
self.config[k] = v
log[k] = [config_ref.get(k), v]
strategy = policy_config.get('strategy')
if strategy: # final policy