~ubuntu-branches/ubuntu/utopic/spew/utopic

« back to all changes in this revision

Viewing changes to src/Log.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matt Taggart
  • Date: 2005-02-02 01:42:02 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050202014202-mkxgmw1k13b3p5mv
Tags: 1.0.4-1
* New upstream release
* Upstream fixed file conflict with snarf, Closes: #279679, #292316
* Drop libstdc++ build-dep. I should know better, I've filed bugs on
   other packages for the same thing :(,  Closes: #280257
* Add AUTHORS file to debian/docs
* Upstream fixed various DESTDIR problems, removed from diff
* Fix lintian description warnings

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
////////////////////////  Local constants  ////////////////////////////////////
38
38
///////////////////////////////////////////////////////////////////////////////
39
39
int TIMESTAMP_STR_LEN = 19;  // Does not includes space for \0.
40
 
 
 
40
char LOGFILE_SEPARATOR_CHAR = '#';
 
41
int LOGFILE_WIDTH = 80;
41
42
 
42
43
 
43
44
//////////////////////////  Log::Log()  ///////////////////////////////////////
231
232
      return;
232
233
 
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);
 
236
 
 
237
   fprintf(mLogStdoutFile, "%s\n",
 
238
           string(LOGFILE_WIDTH, LOGFILE_SEPARATOR_CHAR).c_str());
 
239
   this->logSeparatorNote(timestamp, "START");
236
240
   fprintf(mLogStdoutFile, "\n");
237
 
 
238
241
}
239
242
 
240
243
 
245
248
      return;
246
249
 
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);
252
252
 
 
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");
253
258
}
254
259
 
255
260
 
256
261
//////////////////////////  Log::logCmdLine()  ///////////////////////////////
257
 
void Log::logCmdLine(int argc, char **argv) const
 
262
void Log::logCmdLine(const char *args) const
258
263
{
259
264
   if (!mLogStderrFile)
260
265
      return;
261
 
 
262
 
   fprintf(mLogStdoutFile, "Command-line: ");
263
 
   if (argc > 0)
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 = "\\";
 
269
 
 
270
   string msg = args;
 
271
   this->justify(msg, leader, indent, follower);
 
272
 
 
273
   fprintf(mLogStdoutFile, "%s\n", msg.c_str());
 
274
}
 
275
 
 
276
 
 
277
//////////////////////////  Log::logSeparator()  //////////////////////////////
 
278
void Log::logSeparatorNote(const char *timestamp, const char *note) const
 
279
{
 
280
   if (!mLogStdoutFile)
 
281
      return;
 
282
 
 
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)
 
287
      followerLen += 1;
 
288
 
 
289
   fprintf(mLogStdoutFile, "%s  %s  %s  %s\n", 
 
290
           string(leaderLen, LOGFILE_SEPARATOR_CHAR).c_str(),
 
291
           timestamp, 
 
292
           note,
 
293
           string(followerLen, LOGFILE_SEPARATOR_CHAR).c_str());
268
294
}
269
295
 
270
296
 
285
311
}
286
312
 
287
313
 
 
314
//////////////////////////  Log::justify()  ///////////////////////////////////
 
315
string& Log::justify(string& str, 
 
316
                     const string& leader, 
 
317
                     const string& hangingIndent,
 
318
                     const string& follower) const
 
319
{
 
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;
 
328
 
 
329
   str = leader;
 
330
   curOrigPos = 0;
 
331
   curLinePos = leaderLen;
 
332
   while (curOrigPos < origLen)
 
333
   {
 
334
      spacePos = origStr.find(' ', curOrigPos);
 
335
      if (spacePos != string::npos)
 
336
      {
 
337
         // Skip over successive or leading spaces.
 
338
         if (curOrigPos == spacePos) 
 
339
         {
 
340
            curOrigPos++;
 
341
            continue;
 
342
         }
 
343
         string word = origStr.substr(curOrigPos, spacePos - curOrigPos);
 
344
         string::size_type wordLen = word.length();
 
345
         if (wordLen + followerLen + curLinePos > LOGFILE_WIDTH)
 
346
         {
 
347
            str += follower;
 
348
            str += "\n";
 
349
            str += hangingIndent;
 
350
            curLinePos = indentLen + wordLen + 1;
 
351
         }
 
352
         else
 
353
            curLinePos += wordLen + 1;
 
354
         str += word;
 
355
         str += " "; 
 
356
      curOrigPos = spacePos + 1;
 
357
      }
 
358
      else
 
359
      {
 
360
         str += origStr.substr(curOrigPos, origLen - curOrigPos);
 
361
         str += "\n";
 
362
         break;
 
363
      }
 
364
   }
 
365
 
 
366
   return str;
 
367
}
 
368
 
 
369
 
288
370
//////////////////////////  Log::~Log()  //////////////////////////////////////
289
371
Log::~Log()
290
372
{