Logo
~Sockets~
~Examples~
~Contact~


StdoutLog.cpp

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2004-2007  Anders Hedstrom
00007 
00008 This library is made available under the terms of the GNU GPL.
00009 
00010 If you would like to use this library in a closed-source application,
00011 a separate license agreement is available. For information about 
00012 the closed-source license agreement for the C++ sockets library,
00013 please visit http://www.alhem.net/Sockets/license.html and/or
00014 email license@alhem.net.
00015 
00016 This program is free software; you can redistribute it and/or
00017 modify it under the terms of the GNU General Public License
00018 as published by the Free Software Foundation; either version 2
00019 of the License, or (at your option) any later version.
00020 
00021 This program is distributed in the hope that it will be useful,
00022 but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 GNU General Public License for more details.
00025 
00026 You should have received a copy of the GNU General Public License
00027 along with this program; if not, write to the Free Software
00028 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00029 */
00030 #ifdef _WIN32
00031 #pragma warning(disable:4786)
00032 #endif
00033 #include "ISocketHandler.h"
00034 #include "Socket.h"
00035 #include "StdoutLog.h"
00036 
00037 #ifdef SOCKETS_NAMESPACE
00038 namespace SOCKETS_NAMESPACE {
00039 #endif
00040 
00041 
00042 
00043 
00044 void StdoutLog::error(ISocketHandler *,Socket *sock,const std::string& call,int err,const std::string& sys_err,loglevel_t lvl)
00045 {
00046         time_t t = time(NULL);
00047         struct tm tp;
00048 #ifdef _WIN32
00049         memcpy(&tp, localtime(&t), sizeof(tp));
00050 #else
00051         localtime_r(&t, &tp);
00052 #endif
00053         std::string level;
00054         
00055         switch (lvl)
00056         {
00057         case LOG_LEVEL_WARNING:
00058                 level = "Warning";
00059                 break;
00060         case LOG_LEVEL_ERROR:
00061                 level = "Error";
00062                 break;
00063         case LOG_LEVEL_FATAL:
00064                 level = "Fatal";
00065                 break;
00066         case LOG_LEVEL_INFO:
00067                 level = "Info";
00068                 break;
00069         }
00070         if (sock)
00071         {
00072                 printf("%d-%02d-%02d %02d:%02d:%02d :: fd %d :: %s: %d %s (%s)\n",
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                         sock -> GetSocket(),
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: %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                         call.c_str(),err,sys_err.c_str(),level.c_str());
00088         }
00089 }
00090 
00091 
00092 #ifdef SOCKETS_NAMESPACE
00093 }
00094 #endif
00095 
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4