00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016 #include <iomanip>
00017 #include <string.h>
00018
00019 #include "assa/TimeVal.h"
00020 #include "assa/Logger_Impl.h"
00021
00022 #if defined (WIN32)
00023 # include <windows.h>
00024 #endif
00025
00026 using namespace ASSA;
00027
00028 char Logger_Impl::m_msgbuf [LOGGER_MAXLINE];
00029
00030 u_short
00031 Logger_Impl::
00032 add_timestamp (ostream& sink_)
00033 {
00034
00035 u_short bytecount = 0;
00036
00037 if (timestamp_enabled ()) {
00038 TimeVal tv = TimeVal::gettimeofday ();
00039 tv.tz (m_tz);
00040 sink_ << tv.fmtString ("%m/%d/%Y %H:%M:%S") << '.';
00041 char oldfill = sink_.fill('0');
00042 sink_ << std::setw (3) << (tv.msec () % 1000000)/1000 << ' ';
00043 sink_.fill (oldfill);
00044 bytecount = 23;
00045 }
00046 return bytecount;
00047 }
00048
00049 u_short
00050 Logger_Impl::
00051 indent_func_name (ostream& sink_,
00052 const string& func_name_,
00053 size_t indent_level_,
00054 marker_t type_)
00055 {
00056 u_short bytecount = 0;
00057
00058 if (func_name_.size ()) {
00059 u_int i = 1;
00060 while (i < indent_level_) {
00061 sink_ << '|';
00062 for (u_short j = 0; j < m_indent_step-1; j++) {
00063 sink_ << ' ';
00064 }
00065 i++;
00066 }
00067 if (type_ == FUNC_ENTRY) {
00068 sink_ << '/' << func_name_ << " ";
00069 }
00070 else if (type_ == FUNC_EXIT) {
00071 sink_ << '\\' << func_name_ << " ";
00072 }
00073 else if (type_ == FUNC_MSG) {
00074 sink_ << '[' << func_name_ << "] ";
00075 }
00076 bytecount += indent_level_ * m_indent_step + func_name_.size () + 3;
00077 }
00078 return bytecount;
00079 }
00080
00081 char*
00082 Logger_Impl::
00083 format_msg (size_t expected_sz_,
00084 const char* fmt_,
00085 va_list vap_,
00086 bool& release_)
00087 {
00088 char* msg = m_msgbuf;
00089 int ret = 0;
00090
00091 release_ = false;
00092 expected_sz_++;
00093
00094 if (expected_sz_ >= LOGGER_MAXLINE) {
00095 msg = new char [expected_sz_];
00096 release_ = true;
00097 }
00098
00099 ret = ::vsnprintf (msg, expected_sz_, fmt_, vap_);
00100 #if NEVER
00101 if (ret < 0) {
00102 std::cout << "Logger_Impl: format_mg(expected_sz=" << expected_sz_
00103 << ")=-1 failed! errno=" << errno << " ("
00104 << strerror(errno) << "\n" << std::flush;
00105 }
00106 #endif
00107
00108 return (ret < 0 ? NULL : msg);
00109 }