233
234
char timestamp[TIMESTAMP_STR_LEN + 1];
234
fprintf(mLogStdoutFile, "###############################################################################\n");
235
fprintf(mLogStdoutFile, "####################### %s START ##########################\n", this->timestamp(timestamp));
235
this->timestamp(timestamp);
237
fprintf(mLogStdoutFile, "%s\n",
238
string(LOGFILE_WIDTH, LOGFILE_SEPARATOR_CHAR).c_str());
239
this->logSeparatorNote(timestamp, "START");
236
240
fprintf(mLogStdoutFile, "\n");
247
250
char timestamp[TIMESTAMP_STR_LEN + 1];
248
fprintf(mLogStdoutFile, "\n");
249
fprintf(mLogStdoutFile, "####################### %s FINISH #########################\n", this->timestamp(timestamp));
250
fprintf(mLogStdoutFile, "###############################################################################\n");
251
fprintf(mLogStdoutFile, "\n");
251
this->timestamp(timestamp);
253
fprintf(mLogStdoutFile, "\n");
254
this->logSeparatorNote(timestamp, "FINISH");
255
fprintf(mLogStdoutFile, "%s\n",
256
string(LOGFILE_WIDTH, LOGFILE_SEPARATOR_CHAR).c_str());
257
fprintf(mLogStdoutFile, "\n");
256
261
////////////////////////// Log::logCmdLine() ///////////////////////////////
257
void Log::logCmdLine(int argc, char **argv) const
262
void Log::logCmdLine(const char *args) const
259
264
if (!mLogStderrFile)
262
fprintf(mLogStdoutFile, "Command-line: ");
264
fprintf(mLogStdoutFile, "%s ", basename(argv[0]));
265
for (int i = 1; i < argc; i++)
266
fprintf(mLogStdoutFile, "%s ", argv[i]);
267
fprintf(mLogStdoutFile, "\n");
266
const char *leader = "Command-line: ";
267
const char *indent = " ";
268
const char *follower = "\\";
271
this->justify(msg, leader, indent, follower);
273
fprintf(mLogStdoutFile, "%s\n", msg.c_str());
277
////////////////////////// Log::logSeparator() //////////////////////////////
278
void Log::logSeparatorNote(const char *timestamp, const char *note) const
283
int noteLen = strlen(timestamp) + strlen(note) + 6;
284
int leaderLen = (LOGFILE_WIDTH - noteLen)/2;
285
int followerLen = leaderLen;
286
if (((LOGFILE_WIDTH - noteLen) % 2) == 1)
289
fprintf(mLogStdoutFile, "%s %s %s %s\n",
290
string(leaderLen, LOGFILE_SEPARATOR_CHAR).c_str(),
293
string(followerLen, LOGFILE_SEPARATOR_CHAR).c_str());
314
////////////////////////// Log::justify() ///////////////////////////////////
315
string& Log::justify(string& str,
316
const string& leader,
317
const string& hangingIndent,
318
const string& follower) const
320
string origStr = str;
321
string::size_type leaderLen = leader.length();
322
string::size_type indentLen = hangingIndent.length();
323
string::size_type followerLen = follower.length();
324
string::size_type origLen = origStr.length();
325
string::size_type curOrigPos = 0;
326
string::size_type spacePos = string::npos;
327
string::size_type curLinePos = 0;
331
curLinePos = leaderLen;
332
while (curOrigPos < origLen)
334
spacePos = origStr.find(' ', curOrigPos);
335
if (spacePos != string::npos)
337
// Skip over successive or leading spaces.
338
if (curOrigPos == spacePos)
343
string word = origStr.substr(curOrigPos, spacePos - curOrigPos);
344
string::size_type wordLen = word.length();
345
if (wordLen + followerLen + curLinePos > LOGFILE_WIDTH)
349
str += hangingIndent;
350
curLinePos = indentLen + wordLen + 1;
353
curLinePos += wordLen + 1;
356
curOrigPos = spacePos + 1;
360
str += origStr.substr(curOrigPos, origLen - curOrigPos);
288
370
////////////////////////// Log::~Log() //////////////////////////////////////