diff --git a/README.md b/README.md index 2437629..90ee43b 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/charge_lnd/charge_lnd.py b/charge_lnd/charge_lnd.py index 29b0a6b..c17f116 100755 --- a/charge_lnd/charge_lnd.py +++ b/charge_lnd/charge_lnd.py @@ -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") diff --git a/charge_lnd/fmt.py b/charge_lnd/fmt.py index cc7fdc2..a55d0be 100644 --- a/charge_lnd/fmt.py +++ b/charge_lnd/fmt.py @@ -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)) diff --git a/charge_lnd/policy.py b/charge_lnd/policy.py index cc14d29..a06100a 100644 --- a/charge_lnd/policy.py +++ b/charge_lnd/policy.py @@ -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