/build/buildd/libassa-3.4.1/assa/Logger_Impl.cpp

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //------------------------------------------------------------------------------
00003 //                              assa/Logger_Impl.cpp
00004 //------------------------------------------------------------------------------
00005 // $Id: Logger_Impl.cpp,v 1.4 2005/12/17 19:53:29 vlg Exp $
00006 //------------------------------------------------------------------------------
00007 //  Copyright (c) 2001 by Vladislav Grinchenko
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Library General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2 of the License, or (at your option) any later version.
00013 //------------------------------------------------------------------------------
00014 
00015 #include <iostream>
00016 #include <iomanip>
00017 
00018 #include "assa/TimeVal.h"
00019 #include "assa/Logger_Impl.h"
00020 
00021 using namespace ASSA;
00022 
00023 char Logger_Impl::m_msgbuf [LOGGER_MAXLINE];
00024 
00025 u_short 
00026 Logger_Impl::
00027 add_timestamp (ostream& sink_)
00028 {
00029     /*--- 'DD/MM/CC HH:MM:SS.MMMM ' - 23 chars ---*/
00030     u_short bytecount = 0;
00031 
00032     if (timestamp_enabled ()) {
00033         TimeVal tv = TimeVal::gettimeofday ();
00034         tv.tz (m_tz);
00035         sink_ << tv.fmtString ("%m/%d/%G %T") << '.';
00036         char oldfill = sink_.fill('0');
00037         sink_ << std::setw (3) << (tv.msec () % 1000000)/1000 << ' ';
00038         sink_.fill (oldfill);
00039         bytecount = 23;
00040     }
00041     return bytecount;
00042 }
00043 
00044 u_short 
00045 Logger_Impl::
00046 indent_func_name (ostream&      sink_,  
00047                   const string& func_name_,
00048                   size_t        indent_level_,
00049                   marker_t      type_)
00050 {
00051     u_short bytecount = 0;
00052 
00053     if (func_name_.size ()) {
00054         u_int i = 1; 
00055         while (i < indent_level_) { 
00056             sink_ << '|';
00057             for (u_short j = 0; j < m_indent_step-1; j++) {
00058                 sink_ << ' ';
00059             }
00060             i++;
00061         }
00062         if (type_ == FUNC_ENTRY) {
00063             sink_ << '/' << func_name_ << "  ";
00064         }
00065         else if (type_ == FUNC_EXIT) {
00066             sink_ << '\\' << func_name_ << "  ";
00067         }
00068         else if (type_ == FUNC_MSG) {
00069             sink_ << '[' << func_name_ << "] ";
00070         }
00071         bytecount += indent_level_ * m_indent_step + func_name_.size () + 3;
00072     }
00073     return bytecount;
00074 }
00075 
00076 char* 
00077 Logger_Impl::
00078 format_msg (size_t expected_sz_, 
00079             const char* fmt_, 
00080             va_list vap_, 
00081             bool& release_)
00082 {
00083     release_ = false;
00084     char* msg = m_msgbuf;
00085     expected_sz_++;             // Expected size includes '\0'
00086 
00087     if (expected_sz_ >= LOGGER_MAXLINE) {
00088         msg = new char [expected_sz_];
00089         release_ = true;
00090     }
00091     if (::vsnprintf (msg, expected_sz_, fmt_, vap_) < 0) {
00092         return NULL;
00093     }
00094     return msg;
00095 }

Generated on Thu Jun 22 12:39:20 2006 for libassa by  doxygen 1.4.6