Logo
~Apps~
~Projects~
~Contact~


MyLog.cpp

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2004,2005  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 #ifdef _WIN32
00024 #pragma warning(disable:4786)
00025 #endif
00026 #include <stdio.h>
00027 #include <time.h>
00028 #include <ISocketHandler.h>
00029 #include <Socket.h>
00030 #include <typeinfo>
00031 #include "PeerHandler.h"
00032 #include "pSocket.h"
00033 #include "MyLog.h"
00034 
00035 
00036 
00037 
00038 void MyLog::error(ISocketHandler *h,Socket *sock,const std::string& call,int err,const std::string& sys_err,loglevel_t lvl)
00039 {
00040         PeerHandler& ref = static_cast<PeerHandler&>(*h);
00041         pSocket *csock = dynamic_cast<pSocket *>(sock);
00042         time_t t = time(NULL);
00043         struct tm *tp = localtime(&t);
00044         std::string level;
00045         
00046         switch (lvl)
00047         {
00048         case LOG_LEVEL_WARNING:
00049                 level = "Warning";
00050                 break;
00051         case LOG_LEVEL_ERROR:
00052                 level = "Error";
00053                 break;
00054         case LOG_LEVEL_FATAL:
00055                 level = "Fatal";
00056                 break;
00057         case LOG_LEVEL_INFO:
00058                 level = "Info";
00059                 break;
00060         }
00061 
00062         if (ref.GetDebug() & 2048)
00063         {
00064                 std::string hname;
00065                 std::string sname;
00066                 if (h)
00067                         hname = typeid(h).name();
00068                 if (sock)
00069                         sname = typeid(sock).name();
00070                 if (csock)
00071                 {
00072                 ref.dprintf(csock -> GetSockId(), "%d-%02d-%02d %02d:%02d:%02d :: %s/%s; %s: %d %s (%s)",
00073                         tp -> tm_year + 1900,
00074                         tp -> tm_mon + 1,
00075                         tp -> tm_mday,
00076                         tp -> tm_hour,tp -> tm_min,tp -> tm_sec,
00077                         hname.c_str(), sname.c_str(),
00078                         call.c_str(),err,sys_err.c_str(),level.c_str());
00079                 }
00080                 else
00081                 {
00082                 printf("%d-%02d-%02d %02d:%02d:%02d :: %s/%s; %s: %d %s (%s)\n",
00083                         tp -> tm_year + 1900,
00084                         tp -> tm_mon + 1,
00085                         tp -> tm_mday,
00086                         tp -> tm_hour,tp -> tm_min,tp -> tm_sec,
00087                         hname.c_str(), sname.c_str(),
00088                         call.c_str(),err,sys_err.c_str(),level.c_str());
00089                 }
00090         }
00091 }
00092 
00093 
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4