summaryrefslogtreecommitdiffstats
path: root/src/Logging.cpp
diff options
context:
space:
mode:
authorWim van Aarle <wimvanaarle@gmail.com>2015-05-26 15:43:08 +0200
committerWim van Aarle <wimvanaarle@gmail.com>2015-05-26 15:43:08 +0200
commit3117c7a61a83ca28ba00211d1eb65eaf13a7307a (patch)
tree4851ae878cf499deb2ae2f77575b3c48ecaf5d04 /src/Logging.cpp
parent9e884e760b71be354c08892f6bce2efe723917b3 (diff)
parent57668bcdd086145eb14598e32fd5d0dca711865c (diff)
downloadastra-3117c7a61a83ca28ba00211d1eb65eaf13a7307a.tar.gz
astra-3117c7a61a83ca28ba00211d1eb65eaf13a7307a.tar.bz2
astra-3117c7a61a83ca28ba00211d1eb65eaf13a7307a.tar.xz
astra-3117c7a61a83ca28ba00211d1eb65eaf13a7307a.zip
Merge remote-tracking branch 'upstream/master' into parallel_vec
Conflicts: astra_vc11.vcxproj.filters python/astra/functions.py src/ParallelBeamBlobKernelProjector2D.cpp src/ProjectionGeometry2D.cpp
Diffstat (limited to 'src/Logging.cpp')
-rw-r--r--src/Logging.cpp184
1 files changed, 184 insertions, 0 deletions
diff --git a/src/Logging.cpp b/src/Logging.cpp
new file mode 100644
index 0000000..8290ca0
--- /dev/null
+++ b/src/Logging.cpp
@@ -0,0 +1,184 @@
+/*
+-----------------------------------------------------------------------
+Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp
+ 2014-2015, CWI, Amsterdam
+
+Contact: astra@uantwerpen.be
+Website: http://sf.net/projects/astra-toolbox
+
+This file is part of the ASTRA Toolbox.
+
+
+The ASTRA Toolbox is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+The ASTRA Toolbox is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
+
+-----------------------------------------------------------------------
+$Id$
+*/
+
+#define CLOG_MAIN
+#include <astra/clog.h>
+
+#include <astra/Logging.h>
+
+#include <cstdio>
+
+using namespace astra;
+
+void CLogger::enableScreen()
+{
+ m_bEnabledScreen = true;
+}
+
+void CLogger::enableFile()
+{
+ m_bEnabledFile = true;
+}
+
+void CLogger::enable()
+{
+ enableScreen();
+ enableFile();
+}
+
+void CLogger::disableScreen()
+{
+ m_bEnabledScreen = false;
+}
+
+void CLogger::disableFile()
+{
+ m_bEnabledFile = false;
+}
+
+void CLogger::disable()
+{
+ disableScreen();
+ disableFile();
+}
+
+void CLogger::debug(const char *sfile, int sline, const char *fmt, ...)
+{
+ _assureIsInitialized();
+ va_list ap;
+ va_start(ap, fmt);
+ if(m_bEnabledScreen) clog_debug(sfile,sline,0,fmt,ap);
+ if(m_bEnabledFile && m_bFileProvided) clog_debug(sfile,sline,1,fmt,ap);
+}
+
+void CLogger::info(const char *sfile, int sline, const char *fmt, ...)
+{
+ _assureIsInitialized();
+ va_list ap;
+ va_start(ap, fmt);
+ if(m_bEnabledScreen) clog_info(sfile,sline,0,fmt,ap);
+ if(m_bEnabledFile && m_bFileProvided) clog_info(sfile,sline,1,fmt,ap);
+}
+
+void CLogger::warn(const char *sfile, int sline, const char *fmt, ...)
+{
+ _assureIsInitialized();
+ va_list ap;
+ va_start(ap, fmt);
+ if(m_bEnabledScreen) clog_warn(sfile,sline,0,fmt,ap);
+ if(m_bEnabledFile && m_bFileProvided) clog_warn(sfile,sline,1,fmt,ap);
+}
+
+void CLogger::error(const char *sfile, int sline, const char *fmt, ...)
+{
+ _assureIsInitialized();
+ va_list ap;
+ va_start(ap, fmt);
+ if(m_bEnabledScreen) clog_error(sfile,sline,0,fmt,ap);
+ if(m_bEnabledFile && m_bFileProvided) clog_error(sfile,sline,1,fmt,ap);
+}
+
+void CLogger::_setLevel(int id, log_level m_eLevel)
+{
+ switch(m_eLevel){
+ case LOG_DEBUG:
+ clog_set_level(id,CLOG_DEBUG);
+ break;
+ case LOG_INFO:
+ clog_set_level(id,CLOG_INFO);
+ break;
+ case LOG_WARN:
+ clog_set_level(id,CLOG_WARN);
+ break;
+ case LOG_ERROR:
+ clog_set_level(id,CLOG_ERROR);
+ break;
+ }
+}
+
+void CLogger::setOutputScreen(int fd, log_level m_eLevel)
+{
+ _assureIsInitialized();
+ if(fd==1||fd==2){
+ clog_set_fd(0, fd);
+ }else{
+ error(__FILE__,__LINE__,"Invalid file descriptor");
+ }
+ _setLevel(0,m_eLevel);
+}
+
+void CLogger::setOutputFile(const char *filename, log_level m_eLevel)
+{
+ if(m_bFileProvided){
+ clog_free(1);
+ m_bFileProvided=false;
+ }
+ if(!clog_init_path(1,filename)){
+ m_bFileProvided=true;
+ _setLevel(1,m_eLevel);
+ }
+}
+
+void CLogger::_assureIsInitialized()
+{
+ if(!m_bInitialized)
+ {
+ clog_init_fd(0, 2);
+ clog_set_level(0, CLOG_INFO);
+ clog_set_fmt(0, "%l: %m\n");
+ m_bInitialized = true;
+ }
+}
+
+void CLogger::setFormatFile(const char *fmt)
+{
+ if(m_bFileProvided){
+ clog_set_fmt(1,fmt);
+ }else{
+ error(__FILE__,__LINE__,"No log file specified");
+ }
+}
+void CLogger::setFormatScreen(const char *fmt)
+{
+ clog_set_fmt(0,fmt);
+}
+
+CLogger::CLogger()
+{
+ ;
+}
+
+bool CLogger::setCallbackScreen(void (*cb)(const char *msg, size_t len)){
+ _assureIsInitialized();
+ return clog_set_cb(0,cb)==0;
+}
+
+bool CLogger::m_bEnabledScreen = true;
+bool CLogger::m_bEnabledFile = true;
+bool CLogger::m_bFileProvided = false;
+bool CLogger::m_bInitialized = false;