logger.h
Go to the documentation of this file.
1 /***********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
5  * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
6  *
7  * THE BSD LICENSE
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *************************************************************************/
30 
31 #ifndef RTABMAP_FLANN_LOGGER_H
32 #define RTABMAP_FLANN_LOGGER_H
33 
34 #include <stdio.h>
35 #include <stdarg.h>
36 
37 #include "rtflann/defines.h"
38 
39 
40 namespace rtflann
41 {
42 
43 class Logger
44 {
46 
48  {
49  if ((stream!=NULL)&&(stream!=stdout)) {
50  fclose(stream);
51  }
52  }
53 
54  static Logger& instance()
55  {
56  static Logger logger;
57  return logger;
58  }
59 
60  void _setDestination(const char* name)
61  {
62  if (name==NULL) {
63  stream = stdout;
64  }
65  else {
66  stream = fopen(name,"w");
67  if (stream == NULL) {
68  stream = stdout;
69  }
70  }
71  }
72 
73  int _log(int level, const char* fmt, va_list arglist)
74  {
75  if (level > logLevel ) return -1;
76  int ret = vfprintf(stream, fmt, arglist);
77  return ret;
78  }
79 
80 public:
85  static void setLevel(int level) { instance().logLevel = level; }
86 
91  static int getLevel() { return instance().logLevel; }
92 
97  static void setDestination(const char* name) { instance()._setDestination(name); }
98 
105  static int log(int level, const char* fmt, ...)
106  {
107  va_list arglist;
108  va_start(arglist, fmt);
109  int ret = instance()._log(level,fmt,arglist);
110  va_end(arglist);
111  return ret;
112  }
113 
114 #define LOG_METHOD(NAME,LEVEL) \
115  static int NAME(const char* fmt, ...) \
116  { \
117  va_list ap; \
118  va_start(ap, fmt); \
119  int ret = instance()._log(LEVEL, fmt, ap); \
120  va_end(ap); \
121  return ret; \
122  }
123 
129 
130 private:
131  FILE* stream;
132  int logLevel;
133 };
134 
135 }
136 
137 #endif //RTABMAP_FLANN_LOGGER_H
#define NULL
FILE * stream
Definition: logger.h:131
static void setDestination(const char *name)
Definition: logger.h:97
#define LOG_METHOD(NAME, LEVEL)
Definition: logger.h:114
static int getLevel()
Definition: logger.h:91
int _log(int level, const char *fmt, va_list arglist)
Definition: logger.h:73
static void setLevel(int level)
Definition: logger.h:85
static Logger & instance()
Definition: logger.h:54
static int log(int level, const char *fmt,...)
Definition: logger.h:105
void _setDestination(const char *name)
Definition: logger.h:60


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:59