static void create_warn_message(char *warn_message, int coredumped) { char *tmp; int len; char hostname[128]; bzero(hostname, 128); if (gethostname(hostname, 128) < 0) { write_log(fdlogwf, WARNING, "unable to gethostname\n", "", ""); } if ((tmp = strstr(hostname, ".baidu.com")) != NULL) *tmp = '\0'; len = gettimenow(warn_message, 128); snprintf(warn_message + len, 2048 - len , "[Alarm: %s] Service %s exited%s!", hostname, service, (coredumped ? " with coredump" : "")); }
static void write_log(int fd, int level, const char *info0, const char *info1, const char *info2) { struct stat st; int fdx, ret; char tmp[2048]; char timestr[128]; char loglevel[3][16] = { "NOTICE", "WARNING", "FATAL" }; if (fd == fdlog) { if ((ret = stat(status_files[5], &st)) < 0 || st.st_size > 1800000000) { close(fdlog); if (ret == 0) unlink(status_files[5]); fdlog = open_append(status_files[5]); coe(fdlog); } fdx = fdlog; } else if (fd == fdlogwf) { if ((ret = stat(status_files[6], &st)) < 0 || st.st_size > 1800000000) { close(fdlogwf); if (ret == 0) unlink(status_files[6]); fdlogwf = open_append(status_files[6]); coe(fdlogwf); } fdx = fdlogwf; } else return; bzero(timestr, 128); gettimenow(timestr, 128); snprintf(tmp, 2048, "[%s] %s %s%s%s", level >= 0 && level < 3 ? loglevel[level] : "", timestr, info0, info1, info2); write(fdx, tmp, strlen(tmp)); }
std::string getsecs() { boost::posix_time::ptime time_now=gettimenow(); boost::format f("%f"); return str(f % (time_now - time)); }
boost::posix_time::time_duration operator() () const { return gettimenow() - time; }
void reset() { time=gettimenow(); }
timeelapsed() : time ( gettimenow() ) { }