-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdallog.cpp
57 lines (49 loc) · 1.21 KB
/
gdallog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "infra/gdallog.h"
#ifdef INFRA_LOG_ENABLED
#include "infra/cast.h"
#include "infra/enumutils.h"
#include "infra/log.h"
#include <cpl_error.h>
#include <cpl_port.h>
namespace inf::gdal {
static void gdalErrorHandler(CPLErr errClass, int /*err_no*/, const char* msg)
{
switch (errClass) {
case CE_Debug:
Log::debug("GDAL {}", msg);
break;
case CE_Warning:
Log::debug("GDAL {}", msg);
break;
case CE_Failure:
Log::error("GDAL {}", msg);
break;
case CE_Fatal:
Log::critical("GDAL {}", msg);
break;
default:
break;
}
}
static void gdalErrorHandlerLevelOverride(CPLErr /*errClass*/, int /*err_no*/, const char* msg)
{
// read the log level from the pointer value
const auto logLevel = Log::Level(truncate<enum_type_t<Log::Level>>(reinterpret_cast<unsigned long long>(CPLGetErrorHandlerUserData())));
Log::log(logLevel, "GDAL {}", msg);
}
void set_log_handler()
{
CPLSetErrorHandler(&gdalErrorHandler);
}
void set_log_handler(Log::Level levelToUse)
{
CPLSetErrorHandlerEx(&gdalErrorHandlerLevelOverride, reinterpret_cast<void*>(levelToUse));
}
}
#else
namespace inf::gdal {
void set_log_handler()
{
}
}
#endif