Skip to content

Commit

Permalink
Transfers: Specify verbosity level
Browse files Browse the repository at this point in the history
Add -v and -q paramaters to move the logging level up or down. Also allow
log level to be specified directly with --log-level, which overrides -q
and -v.
  • Loading branch information
Hwesta committed Jul 15, 2016
1 parent eb5c9b3 commit 1ea69b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ The `transfers.py` script can be modified to adjust how automated transfers work
* `--files`: If set, start transfers from files as well as folders.
* `--hide`: If set, hides the Transfer and SIP once completed.
* `-c FILE, --config-file FILE`: config file containing file paths for log/database/PID files. Default: log/database/PID files stored in the same directory as the script (not recommended for production)
* `-v, --verbose`: Increase the debugging output. Can be specified multiple times, e.g. `-vv`
* `-q, --quiet`: Decrease the debugging output. Can be specified multiple times, e.g. `-qq`
* `--log-level`: Set the level for debugging output. One of: 'ERROR', 'WARNING', 'INFO', 'DEBUG'. This will override `-q` and `-v`

#### Getting Correct UUIDs and Setting Processing Rules

Expand Down
30 changes: 25 additions & 5 deletions transfers/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_setting(setting, default=None):
return default


def setup(config_file):
def setup(config_file, log_level):
global CONFIG_FILE
CONFIG_FILE = config_file
models.init(get_setting('databasefile', os.path.join(THIS_DIR, 'transfers.db')))
Expand Down Expand Up @@ -90,7 +90,7 @@ def setup(config_file):
},
'loggers': {
'transfer': {
'level': 'INFO', # One of INFO, DEBUG, WARNING, ERROR, CRITICAL
'level': log_level,
'handlers': ['console', 'file'],
},
},
Expand Down Expand Up @@ -397,10 +397,9 @@ def approve_transfer(directory_name, url, am_api_key, am_user):
return None


def main(am_user, am_api_key, ss_user, ss_api_key, ts_uuid, ts_path, depth, am_url, ss_url, transfer_type, see_files, hide_on_complete=False, config_file=None):

setup(config_file)
def main(am_user, am_api_key, ss_user, ss_api_key, ts_uuid, ts_path, depth, am_url, ss_url, transfer_type, see_files, hide_on_complete=False, config_file=None, log_level='INFO'):

setup(config_file, log_level)
LOGGER.info("Waking up")

session = models.Session()
Expand Down Expand Up @@ -491,8 +490,28 @@ def main(am_user, am_api_key, ss_user, ss_api_key, ts_uuid, ts_path, depth, am_u
parser.add_argument('--files', action='store_true', help='If set, start transfers from files as well as folders.')
parser.add_argument('--hide', action='store_true', help='If set, hide the Transfers and SIPs in the dashboard once they complete.')
parser.add_argument('-c', '--config-file', metavar='FILE', help='Configuration file(log/db/PID files)', default=None)

# Logging
parser.add_argument('--verbose', '-v', action='count', default=0, help='Increase the debugging output.')
parser.add_argument('--quiet', '-q', action='count', default=0, help='Decrease the debugging output')
parser.add_argument('--log-level', choices=['ERROR', 'WARNING', 'INFO', 'DEBUG'], default=None, help='Set the debugging output level. This will override -q and -v')

args = parser.parse_args()

log_levels = {
2: 'ERROR',
1: 'WARNING',
0: 'INFO',
-1: 'DEBUG',
}
if args.log_level is None:
level = args.quiet - args.verbose
level = max(level, -1) # No smaller than -1
level = min(level, 2) # No larger than 2
log_level = log_levels[level]
else:
log_level = args.log_level

sys.exit(main(
am_user=args.user,
am_api_key=args.api_key,
Expand All @@ -507,4 +526,5 @@ def main(am_user, am_api_key, ss_user, ss_api_key, ts_uuid, ts_path, depth, am_u
see_files=args.files,
hide_on_complete=args.hide,
config_file=args.config_file,
log_level=log_level,
))

0 comments on commit 1ea69b7

Please sign in to comment.