Beispiel #1
0
def setConsoleLogLevel(lvl):
    from CRABClient.ClientUtilities import setConsoleLogLevelVar
    setConsoleLogLevelVar(lvl)
    if 'CRAB3.all' in logging.getLogger().manager.loggerDict:
        for h in logging.getLogger('CRAB3.all').handlers:
            h.setLevel(lvl)
Beispiel #2
0
def setConsoleLogLevel(lvl):
    from CRABClient.ClientUtilities import setConsoleLogLevelVar
    setConsoleLogLevelVar(lvl)
    if 'CRAB3.all' in logging.getLogger().manager.loggerDict:
        for h in logging.getLogger('CRAB3.all').handlers:
            h.setLevel(lvl)
Beispiel #3
0
    def __call__(self):

        (options, args) = self.parser.parse_args()

        ## The default logfile destination is ./crab.log. It will be changed once we
        ## know/create the CRAB project directory.
        if options.quiet:
            setConsoleLogLevelVar(logging.WARNING)
        elif options.debug:
            setConsoleLogLevelVar(logging.DEBUG)
        self.tblogger, self.logger, self.memhandler = initLoggers()

        #Instructions needed in case of early failures: sometimes the traceback logger
        #has not been set yet.

        ## Will replace Python's sys.excepthook default function with the next function.
        ## This function is used for handling uncaught exceptions (in a Python program
        ## this happens just before the program exits).
        ## In this function:
        ## - make sure everything is logged to the crab.log file;
        ## However, we already have a `finally' clause where we make sure everything is
        ## logged to the crab log file.
        def log_exception(exc_type, exc_value, tback):
            """
            Send a short version of the exception to the console,
            a long version to the log

            Adapted from Doug Hellmann

            This might help sometimes:
            import traceback,pprint;
            pprint.pprint(traceback.format_tb(tback))
            """

            ## Add to the CRAB3 logger a file handler to the log file (if it doesn't have it
            ## already).
            tbLogger = logging.getLogger('CRAB3')
            hasFileHandler = False
            for h in tbLogger.handlers:
                if isinstance(h, logging.FileHandler
                              ) and h.stream.name == client.logger.logfile:
                    hasFileHandler = True
            if not hasFileHandler:
                filehandler = logging.FileHandler(client.logger.logfile)
                filehandler.setFormatter(LOGFORMATTER)
                tbLogger.addHandler(filehandler)
            ## This goes to the log file.
            tbLogger.error("Unhandled Exception!")
            tbLogger.error(exc_value, exc_info=(exc_type, exc_value, tback))

            ## This goes to the console (via the CRAB3.all logger) and to the log file (via
            ## the parent CRAB3 logger).
            logger = logging.getLogger('CRAB3.all')
            logger.error("ERROR: %s: %s", exc_type.__name__, exc_value)
            logger.error(
                "\n\tPlease email %s for support with the crab.log file or crab.log URL.",
                FEEDBACKMAIL)
            logger.error("\tClient Version: %s", client_version)

            logger.error(
                "\tPlease use 'crab uploadlog' to upload the log file %s to the CRAB cache.",
                client.logger.logfile)

        sys.excepthook = log_exception

        # check that the command is valid
        if len(args) == 0:
            print("You have not specified a command.")
            # Described the valid commands in epilog, reuse here
            print(self.parser.epilog)
            sys.exit(-1)

        sub_cmd = None
        try:
            sub_cmd = next(v for k, v in self.subCommands.items()
                           if args[0] in v.shortnames or args[0] == v.name)
        except StopIteration:
            print("'" + str(args[0]) + "' is not a valid command.")
            self.parser.print_help()
            sys.exit(-1)
        self.cmd = sub_cmd(self.logger, args[1:])

        self.cmd()
filelist = get_filelist(
    'DoubleEG', 'T2_IT_Bari',
    [taskname_to_lfn(task) for task in electron_datasets['DoubleEG']])

#Apparently not working with LFN now?
filelist = ['root://cms-xrd-global.cern.ch/%s' % f for f in filelist]

dryrun = False
DEBUG = True
if DEBUG:
    #dryrun=True
    filelist = filelist[:10]
    import logging
    from CRABClient.ClientUtilities import setConsoleLogLevelVar
    setConsoleLogLevelVar(logging.DEBUG)

crabConfig = getConfig('MonoHZZ', '4e', 'FNAL', 'NO', 'DoubleEG', '2017',
                       [str(f) for f in filelist])

if DEBUG:
    crabConfig.Data.unitsPerJob = 1

#crabCommand('submit',config=crabConfig)

#DEBUGGING

#from submit import submit
#from raw_command_debug import crabCommandDebug

extra_args = ['--wait']