// prefix-date.log void logger::init(LOG_LEVEL level, const std::string &path, const std::string &prefix) { std::string rpath; rpath = path; if (path[path.length()] != '/') { rpath.append("/"); } create_dir(rpath.c_str()); rpath.append(prefix); rpath.append(get_current_date()); rpath.append(".log"); set_filename(rpath); //m_file_name = rpath; //std::cout << "File: " << m_file_name << std::endl; m_show_level = level; }
//this function is called when writer thread is sleeping int DbDumperWriter::rotate_date_dir() { char datebuf[MAX_DATE_LEN]; int ret = OB_SUCCESS; get_current_date(datebuf, MAX_DATE_LEN); CThreadGuard guard(&records_lock_); //need to change dir if (current_date_.compare(datebuf)) { std::string tmp_path = path_ + "/" + current_date_ ; tmp_path += "/"; ret = output_files_.output_done(tmp_path); if (ret != OB_SUCCESS) { TBSYS_LOG(ERROR, "can't write done file, path:%s, %d", tmp_path.c_str(), ret); report_msg(MSG_ERROR, "can't write done file, path:%s", tmp_path.c_str()); } TBSYS_LOG(INFO, "max writen files number=[%ld]", log_id_); //finish all tmp file if (ret == OB_SUCCESS) { if (file_ != NULL) { file_->Sync(); delete file_; file_ = NULL; } ret = mv_output_file(); if (ret != OB_SUCCESS) { TBSYS_LOG(ERROR, "can't mv_out_file "); } } if (ret == OB_SUCCESS) { //date has changed, rotate to new dir current_date_ = datebuf; TBSYS_LOG(INFO, "change to new date, %s", current_date_.c_str()); ret = init_output_files(); if (ret != OB_SUCCESS) { TBSYS_LOG(ERROR, "can't change directory"); } } } else { TBSYS_LOG(WARN, "can't roate date dir,because date hasn't changed"); } return ret; }
int DbDumperWriter::start() { int ret = OB_SUCCESS; if (sem_init(&sem_empty_, 0, 0) != 0) { TBSYS_LOG(ERROR, "error when calling sem_init"); ret = OB_ERROR; } if (DUMP_CONFIG->init_date() == NULL) { char datebuf[MAX_DATE_LEN]; get_current_date(datebuf, MAX_DATE_LEN); std::string dir_path = path_ + "/" + datebuf; current_date_ = datebuf; } else { current_date_ = DUMP_CONFIG->init_date(); } TBSYS_LOG(INFO, "[dump writer]:init date=%s", current_date_.c_str()); if (ret == OB_SUCCESS) { ret = init_output_files(); if (ret != OB_SUCCESS) { TBSYS_LOG(ERROR, "when init output files"); } } if (ret == OB_SUCCESS) { thr_ = new(std::nothrow) tbsys::CThread(); if (thr_ == NULL) ret = OB_ERROR; } if (ret == OB_SUCCESS) { running_ = true; thr_->start(this, NULL); } return ret; }
int cmd_log(int argc,const char** argv){ // check necessary param check_cmd_args(argc,argv); char *current=""; while(*argv){ if(!strcmp("-t",*argv)){ argv++; current=(char*)*argv; argv++; }else{ argv++; } } if(!strlen(current)) current=get_current_date(); st_sql_log *logs=get_date_log(current); // while(*logs){ // printf("%s\n", (*logs).sqltime); // } return 1; }