// Initialize a UserLog object for a given job and return a pointer to // the UserLog object created. This object can then be used to write // events and must be deleted when you're done. This returns NULL if // the user didn't want a UserLog, so you must check for NULL before // using the pointer you get back. WriteUserLog* InitializeUserLog( ClassAd *job_ad ) { int cluster, proc; MyString userLogFile, dagmanNodeLog; std::string gjid; bool use_xml = false; std::vector<const char*> logfiles; if( getPathToUserLog(job_ad, userLogFile) ) { logfiles.push_back(userLogFile.Value()); } if( getPathToUserLog(job_ad, dagmanNodeLog, ATTR_DAGMAN_WORKFLOW_LOG) ) { logfiles.push_back(dagmanNodeLog.Value()); } if(logfiles.empty()) { return NULL; } job_ad->LookupInteger( ATTR_CLUSTER_ID, cluster ); job_ad->LookupInteger( ATTR_PROC_ID, proc ); job_ad->LookupString( ATTR_GLOBAL_JOB_ID, gjid ); job_ad->LookupBool( ATTR_ULOG_USE_XML, use_xml ); WriteUserLog *ULog = new WriteUserLog(); ULog->initialize(logfiles, cluster, proc, 0, gjid.c_str()); ULog->setUseXML( use_xml ); return ULog; }
extern "C" void initializeUserLog () { std::string logfilename,dagmanLogName; int use_xml; std::vector<const char*> logfiles; if ( getPathToUserLog(JobAd, logfilename) ) { logfiles.push_back(logfilename.c_str()); dprintf(D_FULLDEBUG, "%s = %s\n", ATTR_ULOG_FILE, logfilename.c_str()); } if ( getPathToUserLog(JobAd, dagmanLogName, ATTR_DAGMAN_WORKFLOW_LOG) ) { logfiles.push_back(dagmanLogName.c_str()); dprintf(D_FULLDEBUG, "%s = %s\n", ATTR_DAGMAN_WORKFLOW_LOG, dagmanLogName.c_str()); } if(!logfiles.empty()) { if ( !ULog.initialize (Proc->owner, NULL, logfiles, Proc->id.cluster, Proc->id.proc, 0)) { EXCEPT("Failed to initialize user log!"); } else { ULog.setUseXML(JobAd->LookupBool(ATTR_ULOG_USE_XML, use_xml) && use_xml); } } else { dprintf(D_FULLDEBUG, "no %s found and no %s found\n", ATTR_ULOG_FILE, ATTR_DAGMAN_WORKFLOW_LOG); } }
extern "C" void initializeUserLog () { MyString logfilename; MyString gjid; int use_xml; bool have_a_log = false; if ( getPathToUserLog(JobAd, logfilename) ) { have_a_log = true; if(JobAd->LookupString(ATTR_GLOBAL_JOB_ID, gjid) != 1) { gjid = "Unknown"; } std::string logfile(logfilename.Value()); WriteUserLog* ulogi = new WriteUserLog; if( !ulogi ) { EXCEPT("Out of memory!\n"); } if (!ulogi->initialize (Proc->owner, NULL, logfilename.Value(), Proc->id.cluster, Proc->id.proc, 0, gjid.Value())) { EXCEPT("Failed to initialize user log!\n"); } ulogi->setUseXML(JobAd->LookupBool(ATTR_ULOG_USE_XML, use_xml) && use_xml); dprintf(D_FULLDEBUG, "%s = %s\n", ATTR_ULOG_FILE, logfilename.Value()); ULog.push_back(ulogi); } if ( getPathToUserLog(JobAd, logfilename, ATTR_DAGMAN_WORKFLOW_LOG) ) { have_a_log = true; if(JobAd->LookupString(ATTR_GLOBAL_JOB_ID, gjid) != 1) { gjid = "Unknown"; } std::string logfile(logfilename.Value()); WriteUserLog* ulogi = new WriteUserLog; if( !ulogi ) { EXCEPT("Out of memory!\n"); } ulogi->setUseXML(false); if (!ulogi->initialize (Proc->owner, NULL, logfilename.Value(), Proc->id.cluster, Proc->id.proc, 0, gjid.Value())) { EXCEPT("Failed to initialize user log!\n"); } dprintf(D_FULLDEBUG, "%s = %s\n", ATTR_ULOG_FILE, logfilename.Value()); if(!ULog.empty()){ // Only write to global event log once ulogi->setEnableGlobalLog( false ); } ULog.push_back(ulogi); } if( !have_a_log ) { dprintf(D_FULLDEBUG, "no %s found\n", ATTR_ULOG_FILE); dprintf(D_FULLDEBUG, "Also, no %s found\n", ATTR_DAGMAN_WORKFLOW_LOG); } }
void BaseShadow::initUserLog() { MyString logfilename,dagmanLogFile; int use_xml; // we expect job_updater to already be initialized, in case we // need to put the job on hold as a result of failure to open // the log ASSERT( job_updater ); std::vector<const char*> logfiles; if ( getPathToUserLog(jobAd, logfilename) ) { logfiles.push_back(logfilename.Value()); dprintf(D_FULLDEBUG, "%s = %s\n", ATTR_ULOG_FILE, logfilename.Value()); } if ( getPathToUserLog(jobAd, dagmanLogFile, ATTR_DAGMAN_WORKFLOW_LOG) ) { logfiles.push_back(dagmanLogFile.Value()); dprintf(D_FULLDEBUG, "%s = %s\n", ATTR_DAGMAN_WORKFLOW_LOG, dagmanLogFile.Value()); } if( !logfiles.empty()) { if( !uLog.initialize (logfiles, cluster, proc, 0, gjid)) { MyString hold_reason; hold_reason.formatstr("Failed to initialize user log to %s%s%s", logfilename.Value(), logfiles.size() == 1 ? "" : " or ", dagmanLogFile.Value()); dprintf( D_ALWAYS, "%s\n",hold_reason.Value()); holdJobAndExit(hold_reason.Value(), CONDOR_HOLD_CODE_UnableToInitUserLog,0); // holdJobAndExit() should not return, but just in case it does // EXCEPT EXCEPT("Failed to initialize user log: %s",hold_reason.Value()); } uLog.setUseXML(jobAd->LookupBool(ATTR_ULOG_USE_XML, use_xml) && use_xml); if(logfiles.size() > 1) { MyString msk; jobAd->LookupString(ATTR_DAGMAN_WORKFLOW_MASK, msk); Tokenize(msk.Value()); dprintf(D_FULLDEBUG, "Mask is \"%s\"\n", msk.Value()); while(const char* mask = GetNextToken(",",true)) { dprintf(D_FULLDEBUG, "Adding \"%s\" to mask\n",mask); uLog.AddToMask(ULogEventNumber(atoi(mask))); } } } else { dprintf(D_FULLDEBUG, "no %s found\n", ATTR_ULOG_FILE); dprintf(D_FULLDEBUG, "and no %s found\n", ATTR_DAGMAN_WORKFLOW_LOG); } }