00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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