📄 vlog.cxx
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const VLog_cxx_Version = "$Id: VLog.cxx,v 1.8 2002/03/16 04:55:31 icahoon Exp $";#include "global.h"#include "VLog.hxx"#include "CpPriorityLog.hxx"#include <cassert>#include <cctype>#include <string>using Vocal::Logging::VLog;using Vocal::Logging::Log;using Vocal::Logging::PriorityLog;using Vocal::Logging::CpPriorityLog;using std::string;Sptr<PriorityLog> VLog::null_ = 0;bool VLog::traceOn_ = false;bool VLog::verboseOn_ = false;VLog::VLog() : emergency_(0), alert_(0), critical_(0), error_(0), warning_(0), notice_(0), info_(0), debug_(0), debugStack_(0), debugOper_(0), debugHB_(0), trace_(traceOn_), verbose_(verboseOn_), funcName_(""){ if ( null_ == 0 ) { init(cpLogGetPriority()); }}VLog::VLog(const string & funcName) : emergency_(0), alert_(0), critical_(0), error_(0), warning_(0), notice_(0), info_(0), debug_(0), debugStack_(0), debugOper_(0), debugHB_(0), trace_(traceOn_), verbose_(verboseOn_), funcName_(funcName){ if ( null_ == 0 ) { init(cpLogGetPriority()); } if ( funcName.size() ) { VTRACE(*this) << "Function Entry: " << funcName << VTRACE_END(*this); }}VLog::~VLog(){ if ( funcName_.size() ) { VTRACE(*this) << "Function Exit: " << funcName_ << VTRACE_END(*this); }} voidVLog::init( int priority, const char * file){ int priorityLevel = priority; if ( priorityLevel > LAST_PRIORITY ) { priorityLevel = LAST_PRIORITY; } // cpLogSetPriority(priorityLevel); if ( file ) { // cpLogOpen's signature is broken, so let's cast away const. // char * f = const_cast<char *>(file); cpLogOpen(f); } null_ = new CpPriorityLog("--NULL---", -1, false, false); registerLog(-1, null_); registerLog(LOG_EMERG, new CpPriorityLog("EMERGENCY", LOG_EMERG, true)); registerLog(LOG_ALERT, new CpPriorityLog("ALRT ", LOG_ALERT, true)); registerLog(LOG_CRIT, new CpPriorityLog("CRITICAL ", LOG_CRIT, true)); registerLog(LOG_ERR, new CpPriorityLog("ERROR ", LOG_ERR, false, false)); registerLog(LOG_WARNING,new CpPriorityLog("WARNING ", LOG_WARNING, false, false)); registerLog(LOG_NOTICE, new CpPriorityLog("NOTICE ", LOG_NOTICE, false, false)); registerLog(LOG_INFO, new CpPriorityLog("INFO ", LOG_INFO, false, false)); registerLog(LOG_DEBUG, new CpPriorityLog("DEBUG ", LOG_DEBUG, false, false)); registerLog(LOG_DEBUG_STACK,new CpPriorityLog("DEBUG_STK", LOG_DEBUG_STACK, false, false)); registerLog(LOG_DEBUG_OPER, new CpPriorityLog("DEBUG_OP ", LOG_DEBUG_OPER, false, false)); registerLog(LOG_DEBUG_HB, new CpPriorityLog("DEBUG_HB ", LOG_DEBUG_HB, false, false)); switch ( priority ) { case LOG_VERBOSE: VLog::on(LOG_VERBOSE); case LOG_TRACE: VLog::on(LOG_TRACE); case LOG_DEBUG_HB: case LOG_DEBUG_OPER: VLog::on(LOG_DEBUG_OPER); case LOG_DEBUG_STACK: VLog::on(LOG_DEBUG_STACK); case LOG_DEBUG: VLog::on(LOG_DEBUG); case LOG_INFO: VLog::on(LOG_INFO); case LOG_NOTICE: VLog::on(LOG_NOTICE); case LOG_WARNING: VLog::on(LOG_WARNING); case LOG_ERR: VLog::on(LOG_ERR); } // You only get heartbeat logging if you explicitly ask for it. // if ( priority == LOG_DEBUG_HB ) { VLog::on(LOG_DEBUG_HB); }} voidVLog::uninit(){ clearLogs(); null_ = 0;}void VLog::on(int priority){ if ( priority == LOG_TRACE ) { traceOn_ = true; priority = LOG_DEBUG_STACK; } if ( priority == LOG_VERBOSE ) { verboseOn_ = true; priority = LOG_DEBUG_STACK; } LogMap::iterator it = log_.find(priority); Sptr<PriorityLog> nullLog = 0; Sptr<PriorityLog> log = ( it == log_.end() ? nullLog : (*it).second ); if ( priority != -1 && log != 0 ) { log->on(); }}void VLog::off(int priority){ if ( priority == LOG_TRACE ) { traceOn_ = false; return; } if ( priority == LOG_VERBOSE ) { verboseOn_ = false; return; } LogMap::iterator it = log_.find(priority); Sptr<PriorityLog> nullLog = 0; Sptr<PriorityLog> log = ( it == log_.end() ? nullLog : (*it).second ); if ( log != 0 ) { log->off(); }} void VLog::logOn(int priority){ if ( priority == LOG_TRACE ) { priority = LOG_DEBUG_STACK; trace_ = true; } if ( priority == LOG_VERBOSE ) { priority = LOG_DEBUG_STACK; verbose_ = true; } LogMap::iterator it = log_.find(priority); Sptr<PriorityLog> nullLog = 0; Sptr<PriorityLog> log = ( it == log_.end() ? nullLog : (*it).second ); if ( priority != -1 && log != 0 ) { switch ( priority ) { case LOG_EMERG: { if ( emergency_ == 0 || emergency_ == VLog::null_ ) { emergency_ = log->clone(); emergency_->on(); } break; } case LOG_ALERT: { if ( alert_ == 0 || alert_ == VLog::null_ ) { alert_ = log->clone(); alert_->on(); } break; } case LOG_CRIT: { if ( critical_ == 0 || critical_ == VLog::null_ ) { critical_ = log->clone(); critical_->on(); } break; } case LOG_ERR: { if ( error_ == 0 || error_ == VLog::null_ ) { error_ = log->clone(); error_->on(); } break; } case LOG_WARNING: { if ( warning_ == 0 || warning_ == VLog::null_ ) { warning_ = log->clone(); warning_->on(); } break; } case LOG_NOTICE: { if ( notice_ == 0 || notice_ == VLog::null_ ) { notice_ = log->clone(); notice_->on(); } break; } case LOG_INFO: { if ( info_ == 0 || info_ == VLog::null_ ) { info_ = log->clone(); info_->on(); } break; } case LOG_DEBUG: { if ( debug_ == 0 || debug_ == VLog::null_ ) { debug_ = log->clone(); debug_->on(); } break; } case LOG_DEBUG_STACK: { if ( debugStack_ == 0 || debugStack_ == VLog::null_ ) { debugStack_ = log->clone(); debugStack_->on(); } break; } case LOG_DEBUG_OPER: { if ( debugOper_ == 0 || debugOper_ == VLog::null_ ) { debugOper_ = log->clone(); debugOper_->on(); } break; } case LOG_DEBUG_HB: { if ( debugHB_ == 0 || debugHB_ == VLog::null_ ) { debugHB_ = log->clone(); debugHB_->on(); } break; } default: { break; } } }}void VLog::logOff(int priority){ if ( priority == LOG_TRACE ) { trace_ = false; return; } if ( priority == LOG_VERBOSE ) { verbose_ = false; return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -