Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/logger/loggable.cppGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 // @author Brett Ponsler (bponsler (at) wpi (dot) edu) 00035 #include "loggable.h" 00036 00037 #include <stdarg.h> 00038 #include <stdio.h> 00039 00040 Loggable::~Loggable() 00041 { 00042 // Delete the logger if it exists 00043 if (this->logger_) 00044 delete this->logger_; 00045 } 00046 00047 Loggable::Loggable() 00048 { 00049 this->logger_ = NULL; 00050 } 00051 00052 ConsoleLogger *Loggable::getLogger() 00053 { 00054 return this->logger_; 00055 } 00056 00057 void Loggable::setLogger() 00058 { 00059 if (this->logger_) 00060 delete this->logger_; 00061 this->logger_ = new ConsoleLogger(); 00062 } 00063 00064 void Loggable::setLogger(std::string prefix) 00065 { 00066 if (this->logger_) 00067 delete this->logger_; 00068 this->logger_ = new ConsoleLogger(prefix.c_str()); 00069 } 00070 00071 void Loggable::setLogger(const char *prefix) 00072 { 00073 if (this->logger_) 00074 delete this->logger_; 00075 this->logger_ = new ConsoleLogger(prefix); 00076 } 00077 00078 void Loggable::setLogger(ConsoleLogger *logger, std::string prefix) 00079 { 00080 if (this->logger_) 00081 delete this->logger_; 00082 this->logger_ = new ConsoleLogger(logger, prefix.c_str()); 00083 } 00084 00085 void Loggable::setLogger(ConsoleLogger *logger, const char *prefix) 00086 { 00087 if (this->logger_) 00088 delete this->logger_; 00089 this->logger_ = new ConsoleLogger(logger, prefix); 00090 } 00091 00092 void Loggable::setLogger(std::string prefix, int color) 00093 { 00094 if (this->logger_) 00095 delete this->logger_; 00096 this->logger_ = new ConsoleLogger(prefix.c_str(), color); 00097 } 00098 00099 void Loggable::setLogger(const char *prefix, int color) 00100 { 00101 if (this->logger_) 00102 delete this->logger_; 00103 this->logger_ = new ConsoleLogger(prefix, color); 00104 } 00105 00106 void Loggable::setLogger(ConsoleLogger *logger, std::string prefix, int color) 00107 { 00108 if (this->logger_) 00109 delete this->logger_; 00110 this->logger_ = new ConsoleLogger(logger, prefix.c_str(), color); 00111 } 00112 00113 void Loggable::setLogger(ConsoleLogger *logger, const char *prefix, int color) 00114 { 00115 if (this->logger_) 00116 delete this->logger_; 00117 this->logger_ = new ConsoleLogger(logger, prefix, color); 00118 } 00119 00120 void Loggable::setLogger(ConsoleLogger *logger) 00121 { 00122 if (this->logger_) 00123 delete this->logger_; 00124 this->logger_ = new ConsoleLogger(logger); 00125 } 00126 00127 void Loggable::debug(int level, const char *str, ...) 00128 { 00129 // Make sure the logger exists 00130 if (this->logger_) 00131 { 00132 // Print all the arguments to the buffer in the formatted string 00133 va_list args; 00134 va_start (args, str); 00135 this->logger_->debug(level, str, args); 00136 va_end (args); 00137 } 00138 } 00139 00140 void Loggable::info(const char *str, ...) 00141 { 00142 // Make sure the logger exists 00143 if (this->logger_) 00144 { 00145 // Print all the arguments to the buffer in the formatted string 00146 va_list args; 00147 va_start (args, str); 00148 this->logger_->info(str, args); 00149 va_end (args); 00150 } 00151 } 00152 00153 void Loggable::warn(const char *str, ...) 00154 { 00155 // Make sure the logger exists 00156 if (this->logger_) 00157 { 00158 // Print all the arguments to the buffer in the formatted string 00159 va_list args; 00160 va_start (args, str); 00161 this->logger_->warn(str, args); 00162 va_end (args); 00163 } 00164 } 00165 00166 void Loggable::error(const char *str, ...) 00167 { 00168 // Make sure the logger exists 00169 if (this->logger_) 00170 { 00171 // Print all the arguments to the buffer in the formatted string 00172 va_list args; 00173 va_start (args, str); 00174 this->logger_->error(str, args); 00175 va_end (args); 00176 } 00177 } 00178 00179 void Loggable::fatal(const char *str, ...) 00180 { 00181 // Make sure the logger exists 00182 if (this->logger_) 00183 { 00184 // Print all the arguments to the buffer in the formatted string 00185 va_list args; 00186 va_start (args, str); 00187 this->logger_->fatal(str, args); 00188 va_end (args); 00189 } 00190 } 00191 00192 void Loggable::red(const char *str, ...) 00193 { 00194 // Make sure the logger exists 00195 if (this->logger_) 00196 { 00197 // Print all the arguments to the buffer in the formatted string 00198 va_list args; 00199 va_start (args, str); 00200 this->logger_->red(str, args); 00201 va_end (args); 00202 } 00203 } 00204 00205 void Loggable::green(const char *str, ...) 00206 { 00207 // Make sure the logger exists 00208 if (this->logger_) 00209 { 00210 // Print all the arguments to the buffer in the formatted string 00211 va_list args; 00212 va_start (args, str); 00213 this->logger_->green(str, args); 00214 va_end (args); 00215 } 00216 } 00217 00218 void Loggable::yellow(const char *str, ...) 00219 { 00220 // Make sure the logger exists 00221 if (this->logger_) 00222 { 00223 // Print all the arguments to the buffer in the formatted string 00224 va_list args; 00225 va_start (args, str); 00226 this->logger_->yellow(str, args); 00227 va_end (args); 00228 } 00229 } 00230 00231 void Loggable::blue(const char *str, ...) 00232 { 00233 // Make sure the logger exists 00234 if (this->logger_) 00235 { 00236 // Print all the arguments to the buffer in the formatted string 00237 va_list args; 00238 va_start (args, str); 00239 this->logger_->blue(str, args); 00240 va_end (args); 00241 } 00242 } 00243 00244 void Loggable::purple(const char *str, ...) 00245 { 00246 // Make sure the logger exists 00247 if (this->logger_) 00248 { 00249 // Print all the arguments to the buffer in the formatted string 00250 va_list args; 00251 va_start (args, str); 00252 this->logger_->purple(str, args); 00253 va_end (args); 00254 } 00255 } 00256 00257 void Loggable::cyan(const char *str, ...) 00258 { 00259 // Make sure the logger exists 00260 if (this->logger_) 00261 { 00262 // Print all the arguments to the buffer in the formatted string 00263 va_list args; 00264 va_start (args, str); 00265 this->logger_->cyan(str, args); 00266 va_end (args); 00267 } 00268 } |