SWIutilLogger.cpp
上传用户:xqtpzdz
上传日期:2022-05-21
资源大小:1764k
文件大小:7k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1. /*****************************************************************************
  2.  *****************************************************************************
  3.  *
  4.  * SWIutilLogger - logging class for SWIutil
  5.  *
  6.  * This provides logging definitions for SWIutil use of VXIlog, along
  7.  * with some convenience macros.
  8.  *
  9.  *****************************************************************************
  10.  ****************************************************************************/
  11. /****************License************************************************
  12.  * Vocalocity OpenVXI
  13.  * Copyright (C) 2004-2005 by Vocalocity, Inc. All Rights Reserved.
  14.  * This program is free software; you can redistribute it and/or
  15.  * modify it under the terms of the GNU General Public License
  16.  * as published by the Free Software Foundation; either version 2
  17.  * of the License, or (at your option) any later version.
  18.  *  
  19.  * This program is distributed in the hope that it will be useful,
  20.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.  * GNU General Public License for more details.
  23.  *
  24.  * You should have received a copy of the GNU General Public License
  25.  * along with this program; if not, write to the Free Software
  26.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  27.  * Vocalocity, the Vocalocity logo, and VocalOS are trademarks or 
  28.  * registered trademarks of Vocalocity, Inc. 
  29.  * OpenVXI is a trademark of Scansoft, Inc. and used under license 
  30.  * by Vocalocity.
  31.  ***********************************************************************/
  32. // -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8
  33. #include "SWIutilInternal.h"
  34. #include "SWIutilLogger.hpp"                // For this class
  35. // -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8
  36. SWIutilLogger::SWIutilLogger(const VXIchar *moduleName, VXIlogInterface *log,
  37.                              VXIunsigned diagTagBase):
  38.   _moduleName(NULL),_log(log), _diagTagBase(diagTagBase)
  39. {
  40.   if (moduleName != NULL)
  41.   {
  42.     _moduleName = new VXIchar[::wcslen(moduleName) + 1];
  43.     if (_moduleName != NULL)
  44.       ::wcscpy(_moduleName, moduleName);
  45.   }
  46. }
  47. SWIutilLogger::SWIutilLogger(const SWIutilLogger& l):
  48.   _moduleName(NULL), _log(l._log), _diagTagBase(l._diagTagBase)
  49. {
  50.   if (l._moduleName != NULL)
  51.   {
  52.     _moduleName = new VXIchar[::wcslen(l._moduleName) + 1];
  53.     if (_moduleName != NULL)
  54.       ::wcscpy(_moduleName, l._moduleName);
  55.   }
  56. }
  57. SWIutilLogger::~SWIutilLogger()
  58. {
  59.   if (_moduleName != NULL)
  60.     delete [] _moduleName;
  61. }
  62. void SWIutilLogger::SetLog(VXIlogInterface *log, VXIunsigned diagTagBase)
  63. {
  64.   _log = log;
  65.   _diagTagBase = diagTagBase;
  66. }
  67. const VXIchar *SWIutilLogger::GetModuleName() const
  68. {
  69.   return _moduleName;
  70. }
  71. VXIlogInterface *SWIutilLogger::GetLog() const
  72. {
  73.   return _log;
  74. }
  75. VXIunsigned SWIutilLogger::GetDiagBase() const
  76. {
  77.   return _diagTagBase;
  78. }
  79. // Determine if a tag is enabled
  80. VXIbool SWIutilLogger::DiagIsEnabled (VXIunsigned tagID) const
  81. {
  82.   if ( ! _log )
  83.     return FALSE;
  84.   return (*_log->DiagnosticIsEnabled)(_log, _diagTagBase + tagID);
  85. }
  86. // Error logging
  87. VXIlogResult
  88. SWIutilLogger::Error (VXIunsigned errorID, const VXIchar *format, ...) const
  89. {
  90.   va_list arguments;
  91.   if ( ! _log )
  92.     return VXIlog_RESULT_FAILURE;
  93.   VXIlogResult rc;
  94.   if ( format ) {
  95.     va_start(arguments, format);
  96.     rc = (*_log->VError)(_log, _moduleName, errorID, format,
  97.  arguments);
  98.     va_end(arguments);
  99.   } else {
  100.     rc = (*_log->Error)(_log, _moduleName, errorID, NULL);
  101.   }
  102.   return rc;
  103. }
  104. // Error logging
  105. VXIlogResult
  106. SWIutilLogger::Error (VXIlogInterface *log, VXIunsigned errorID,
  107.      const VXIchar *format, ...) const
  108. {
  109.   va_list arguments;
  110.   if ( ! log )
  111.     return VXIlog_RESULT_FAILURE;
  112.   VXIlogResult rc;
  113.   if ( format ) {
  114.     va_start(arguments, format);
  115.     rc = (*log->VError)(log, _moduleName, errorID, format, arguments);
  116.     va_end(arguments);
  117.   } else {
  118.     rc = (*log->Error)(log, _moduleName, errorID, NULL);
  119.   }
  120.   return rc;
  121. }
  122. // Error logging, static
  123. VXIlogResult
  124. SWIutilLogger::Error (VXIlogInterface *log, const VXIchar *moduleName,
  125.      VXIunsigned errorID, const VXIchar *format, ...)
  126. {
  127.   va_list arguments;
  128.   if ( ! log )
  129.     return VXIlog_RESULT_FAILURE;
  130.   VXIlogResult rc;
  131.   if ( format ) {
  132.     va_start(arguments, format);
  133.     rc = (*log->VError)(log, moduleName, errorID, format, arguments);
  134.     va_end(arguments);
  135.   } else {
  136.     rc = (*log->Error)(log, moduleName, errorID, NULL);
  137.   }
  138.   return rc;
  139. }
  140. // Diagnostic logging
  141. VXIlogResult
  142. SWIutilLogger::Diag (VXIunsigned tag, const VXIchar *subtag,
  143.    const VXIchar *format, ...) const
  144. {
  145.   va_list arguments;
  146.   if ( ! _log )
  147.     return VXIlog_RESULT_FAILURE;
  148.   VXIlogResult rc;
  149.   if ( format ) {
  150.     va_start(arguments, format);
  151.     rc = (*_log->VDiagnostic)(_log, tag + _diagTagBase, subtag, format,
  152.       arguments);
  153.     va_end(arguments);
  154.   } else {
  155.     rc = (*_log->Diagnostic)(_log, tag + _diagTagBase, subtag, NULL);
  156.   }
  157.   return rc;
  158. }
  159. // Diagnostic logging
  160. VXIlogResult
  161. SWIutilLogger::Diag (VXIlogInterface *log, VXIunsigned tag,
  162.     const VXIchar *subtag, const VXIchar *format, ...) const
  163. {
  164.   va_list arguments;
  165.   if ( ! log )
  166.     return VXIlog_RESULT_FAILURE;
  167.   VXIlogResult rc;
  168.   if ( format ) {
  169.     va_start(arguments, format);
  170.     rc = (*log->VDiagnostic)(log, tag + _diagTagBase, subtag, format,
  171.      arguments);
  172.     va_end(arguments);
  173.   } else {
  174.     rc = (*log->Diagnostic)(log, tag + _diagTagBase, subtag, NULL);
  175.   }
  176.   return rc;
  177. }
  178. // Diagnostic logging, static
  179. VXIlogResult
  180. SWIutilLogger::Diag (VXIlogInterface *log, VXIunsigned diagTagBase,
  181.     VXIunsigned tag, const VXIchar *subtag,
  182.     const VXIchar *format, ...)
  183. {
  184.   va_list arguments;
  185.   if ( ! log )
  186.     return VXIlog_RESULT_FAILURE;
  187.   VXIlogResult rc;
  188.   if ( format ) {
  189.     va_start(arguments, format);
  190.     rc = (*log->VDiagnostic)(log, tag + diagTagBase, subtag, format,
  191.      arguments);
  192.     va_end(arguments);
  193.   } else {
  194.     rc = (*log->Diagnostic)(log, tag + diagTagBase, subtag, NULL);
  195.   }
  196.   return rc;
  197. }
  198. // Diagnostic logging, va args
  199. VXIlogResult
  200. SWIutilLogger::VDiag (VXIunsigned tag, const VXIchar *subtag,
  201.      const VXIchar *format, va_list args) const
  202. {
  203.   if ( ! _log )
  204.     return VXIlog_RESULT_FAILURE;
  205.   VXIlogResult rc;
  206.   if ( format ) {
  207.     rc = (*_log->VDiagnostic)(_log, tag + _diagTagBase, subtag, format, args);
  208.   } else {
  209.     rc = (*_log->Diagnostic)(_log, tag + _diagTagBase, subtag, NULL);
  210.   }
  211.   return rc;
  212. }