projects
/
matthijs
/
projects
/
backupninja.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
action: Create and use a different Logger for each action.
[matthijs/projects/backupninja.git]
/
src
/
lib
/
backupninja
/
action.py
diff --git
a/src/lib/backupninja/action.py
b/src/lib/backupninja/action.py
index b4245f4c236b6a2961ecc6dc8932dd96f4956712..fe1947f4fd2b3c8da7599c1f73e3b161ca0f6d1c 100644
(file)
--- a/
src/lib/backupninja/action.py
+++ b/
src/lib/backupninja/action.py
@@
-22,6
+22,7
@@
""" Running backup actions """
import os
""" Running backup actions """
import os
+import logging
import logging as log
from backupninja import config
import logging as log
from backupninja import config
@@
-52,23
+53,34
@@
def run_action(action_config, opts, global_config):
configuration file. opts are the parsed commandline options,
global_config is the parsed global configuration.
"""
configuration file. opts are the parsed commandline options,
global_config is the parsed global configuration.
"""
+ config_name = os.path.basename(action_config)
# Split the action filename
# Split the action filename
- parts = os.path.basename(
action_config
).split('.')
+ parts = os.path.basename(
config_name
).split('.')
if (len(parts) != 2):
log.error('Invalid action filename: "%s". Should be in the form name.type, where type is a valid handler.' % action_config)
return
(action_name, action_ty) = parts
if (len(parts) != 2):
log.error('Invalid action filename: "%s". Should be in the form name.type, where type is a valid handler.' % action_config)
return
(action_name, action_ty) = parts
- log.info('Running action "%s.%s"', action_name, action_ty)
+
+ action_log = logging.getLogger(config_name)
+ action_log.info('Running')
try:
# Create a handler for this action
try:
# Create a handler for this action
-
handler = handlers.create_handler(action_ty
)
+
action = handlers.create_action(action_ty, logger=action_log
)
# Let the handler load its configuration file
# Let the handler load its configuration file
-
handler
.load_config(action_config)
+
action
.load_config(action_config)
# Run it
# Run it
- handler.run(test=opts.test)
- handler.finish(test=opts.test)
+ action.run(test=opts.test)
+ action.finish(test=opts.test)
+ # Ask the action if there where any failures
+ success = not action.failed
except Exception, e:
except Exception, e:
-
log.error('Running action "%s.%s" failed: %s', action_name, action_ty
, e)
+
action_log.error('Unexpected exception: %s'
, e)
import traceback
log.debug(traceback.format_exc())
import traceback
log.debug(traceback.format_exc())
+ success = False
+
+ if success:
+ action_log.info('Succeeded')
+ else:
+ action_log.info('Failed')