pgRouting  2.2
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Functions Variables Pages
pgr_logger.h
1 /*PGR-MIT******************************************************************
2  *
3  * file pgr_logger.h
4  *
5  Author: Stephen Woodbridge
6  Date: 2014-05-04
7  License: MIT-X
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the MIT License. Please file MIT-LICENSE for details.
11  *
12  *****************************************************************PGR-MIT*/
13 
14 /*
15  pgr_logger.h
16 
17  A simple logging mechanism the can be disabled for production
18  and should work in C or C++ code.
19 
20  USAGE:
21 
22  #define PGR_LOGGERR_ON
23  #undef PGR_LOGGER_ON // turn off logging for production
24 
25  // override the default log file "/tmp/pgr_logger.log"
26  #define PGR_LOGGER_FILE "mylogger.log"
27 
28  #undef PGR_LOGGER_LOC // dont log filename and line number
29  #define PGR_LOGGER_LOC // log filename and line number with log message
30 
31  // include the logger macros and configure based on defines above
32  #include pgr_logger.h
33 
34  // log a message to the log file
35  PGR_LOGF(format, args);
36  PGR_LOGF("%s at %d\n", "this is a message", time());
37  PGR_LOG("just print a string to the log");
38 
39  This will log something like:
40 
41  myfile.cpp:123: this is a message at 1399216875
42  myfile.cpp:124: just print a string to the log
43 
44 */
45 #ifndef PGR_LOGGER_H
46 #define PGR_LOGGER_H
47 
48 #include <stdio.h>
49 
50 #if defined(PGR_LOGGER_LOC)
51 # undef PGR_LOGGER_LOC_
52 # define PGR_LOGGER_LOC_ 1
53 #else
54 # undef PGR_LOGGER_LOC_
55 # define PGR_LOGGER_LOC_ 0
56 #endif
57 
58 #ifndef PGR_LOGGER_FILE
59 # define PGR_LOGGER_FILE "/tmp/pgr_logger.log"
60 #endif
61 
62 #ifdef PGR_LOGGER_ON
63 # define PGR_LOGF(format, ...) { \
64  FILE *fp = fopen(PGR_LOGGER_FILE, "a+"); \
65  if (PGR_LOGGER_LOC_) fprintf(fp, "%s:%d: ", __FILE__, __LINE__); \
66  fprintf(fp, format, __VA_ARGS__); \
67  fclose(fp); }
68 #else // ifndef LOGGER_ON
69 # define PGR_LOGF(format, ...)
70 #endif // ifndef LOGGER_ON
71 
72 #define PGR_LOG(str) PGR_LOGF("%s\n", str)
73 
74 #endif // ifndef PGR_LOGGER_H