Skip to content

Commit

Permalink
logging: add timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz authored and alaaeddineelamri committed Aug 4, 2022
1 parent 88d47f8 commit 421ef4b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
5 changes: 3 additions & 2 deletions core/src/dird/job.cc
Expand Up @@ -1628,8 +1628,9 @@ JobControlRecord* NewDirectorJcr()
{
JobControlRecord* jcr = new_jcr(DirdFreeJcr);
jcr->impl = new JobControlRecordPrivate(my_config->res_head_container_);
Dmsg1(10, "NewDirectorJcr(): res_head_ is at %p\n",
my_config->res_head_container_->res_head_);
Dmsg1(10, "NewDirectorJcr(): res_head_ is at %p %s\n",
my_config->res_head_container_->res_head_,
my_config->res_head_container_->TimeStampAsString().c_str());
return jcr;
}

Expand Down
5 changes: 2 additions & 3 deletions core/src/dird/ua_status.cc
Expand Up @@ -347,9 +347,8 @@ void ListDirStatusHeader(UaContext* ua)
kBareosVersionStrings.GetOsInfo());
bstrftime_nc(dt, sizeof(dt), daemon_start_time);
ua->SendMsg(_("Daemon started %s. Jobs: run=%d, running=%d db:postgresql, %s "
"binary %d shared_count\n"),
dt, num_jobs_run, JobCount(), kBareosVersionStrings.BinaryInfo,
my_config->res_head_container_.use_count());
"binary\n"),
dt, num_jobs_run, JobCount(), kBareosVersionStrings.BinaryInfo);

if (me->secure_erase_cmdline) {
ua->SendMsg(_(" secure erase command='%s'\n"), me->secure_erase_cmdline);
Expand Down
9 changes: 3 additions & 6 deletions core/src/lib/parse_conf.cc
Expand Up @@ -207,6 +207,9 @@ bool ConfigurationParser::ParseConfig()
bool success = ParseConfigFile(config_path.c_str(), nullptr, scan_error_,
scan_warning_);
if (success && ParseConfigReadyCb_) { ParseConfigReadyCb_(*this); }

res_head_container_->timestamp_ = std::chrono::system_clock::now();

return success;
}

Expand Down Expand Up @@ -518,8 +521,6 @@ bool ConfigurationParser::FindConfigPath(PoolMem& full_path)
// when last job also owning finishes
void ConfigurationParser::ReleasePreviousResourceTable()
{
Dmsg1(10, "ConfigurationParser::ReleasePreviousResourceTable: %p\n",
res_head_container_backup_->res_head_);
res_head_container_backup_ = nullptr;
}

Expand All @@ -528,10 +529,6 @@ void ConfigurationParser::ReleasePreviousResourceTable()
void ConfigurationParser::RestoreResourceTable()
{
std::swap(res_head_container_, res_head_container_backup_);
Dmsg1(10, "ConfigurationParser::RestoreResourceTable: %p -> %p\n",
res_head_container_backup_->res_head_, res_head_container_->res_head_);
Dmsg1(10, "ConfigurationParser::RestoreResourceTable: release %p\n",
res_head_container_backup_->res_head_);
res_head_container_backup_ = nullptr;
}

Expand Down
22 changes: 18 additions & 4 deletions core/src/lib/parse_conf.h
Expand Up @@ -418,8 +418,21 @@ class ConfigurationParser {
void SetResourceDefaultsParserPass2(ResourceItem* item);
};


static std::string TPAsString(const std::chrono::system_clock::time_point& tp)
{
std::time_t t = std::chrono::system_clock::to_time_t(tp);
char str[100];
if (!std::strftime(str, sizeof(str), "%F_%H:%M:%S", std::localtime(&t))) {
return std::string("strftime error");
}
std::string ts = str;
return ts;
}

class ResHeadContainer {
public:
std::chrono::time_point<std::chrono::system_clock> timestamp_{};
BareosResource** res_head_ = nullptr;
ConfigurationParser* config_ = nullptr;

Expand All @@ -430,14 +443,13 @@ class ResHeadContainer {
res_head_ = (BareosResource**)malloc(num * sizeof(BareosResource*));

for (int i = 0; i < num; i++) { res_head_[i] = nullptr; }
Dmsg1(10, "ResHeadContainer::ResHeadContainer : res_head_ is at %p\n",
res_head_);
Dmsg1(10, "ResHeadContainer: new res_head_ %p\n", res_head_);
}

~ResHeadContainer()
{
Dmsg1(10, "ResHeadContainer::~ResHeadContainer : freeing res_head at %p\n",
res_head_);
Dmsg1(10, "ResHeadContainer freeing %p %s\n", res_head_,
TPAsString(timestamp_).c_str());
int num = config_->r_num_;
for (int j = 0; j < num; j++) {
config_->FreeResourceCb_(res_head_[j], j);
Expand All @@ -446,6 +458,8 @@ class ResHeadContainer {
free(res_head_);
res_head_ = nullptr;
}

std::string TimeStampAsString() { return TPAsString(timestamp_); }
};


Expand Down

0 comments on commit 421ef4b

Please sign in to comment.