This file is indexed.

/usr/include/mapnik/debug.hpp is in libmapnik-dev 3.0.9+ds-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#ifndef MAPNIK_DEBUG_HPP
#define MAPNIK_DEBUG_HPP

// mapnik (should not depend on anything that need to use this)
#include <mapnik/config.hpp>
#include <mapnik/util/singleton.hpp>
#include <mapnik/util/noncopyable.hpp>

// std
#include <iostream>
#include <sstream>
#include <ostream>
#include <iosfwd>
#include <string>
#include <unordered_map>
#ifdef MAPNIK_THREADSAFE
#include <mutex>
#include <atomic>
#endif

namespace mapnik {


// Global logger class that holds the configuration of severity, format
// and file/console redirection.

class MAPNIK_DECL logger :
        public singleton<logger,CreateStatic>,
        private util::noncopyable
{
public:
    enum severity_type
    {
        debug = 0,
        warn = 1,
        error = 2,
        none = 3
    };

    using severity_map = std::unordered_map<std::string, severity_type>;

    // global security level
    static severity_type get_severity()
    {
        return severity_level_;
    }

    static void set_severity(severity_type severity_level)
    {
//#ifdef MAPNIK_THREADSAFE
//        std::lock_guard<std::mutex> lock(severity_mutex_);
//#endif
        severity_level_ = severity_level;
    }

    // per object security levels
    static severity_type get_object_severity(std::string const& object_name)
    {
        severity_map::iterator it = object_severity_level_.find(object_name);
        if (object_name.empty() || it == object_severity_level_.end())
        {
            return severity_level_;
        }
        else
        {
            return it->second;
        }
    }

    static void set_object_severity(std::string const& object_name,
                                    severity_type const& security_level)
    {
        if (!object_name.empty())
        {
#ifdef MAPNIK_THREADSAFE
            std::lock_guard<std::mutex> lock(severity_mutex_);
#endif
            object_severity_level_[object_name] = security_level;
        }
    }

    static void clear_object_severity()
    {
#ifdef MAPNIK_THREADSAFE
        std::lock_guard<std::mutex> lock(severity_mutex_);
#endif

        object_severity_level_.clear();
    }

    // format
    static std::string const& get_format()
    {
        return format_;
    }

    static void set_format(std::string const& format)
    {
#ifdef MAPNIK_THREADSAFE
        std::lock_guard<std::mutex> lock(format_mutex_);
#endif
        format_ = format;
    }

    // interpolate the format string for output
    static std::string str();

    // output
    static void use_file(std::string const& filepath);
    static void use_console();

private:
    static severity_map object_severity_level_;
    static std::string format_;
    static std::ofstream file_output_;
    static std::string file_name_;
    static std::streambuf* saved_buf_;

#ifdef MAPNIK_THREADSAFE
    static std::atomic<severity_type> severity_level_;
    static std::atomic<bool> severity_env_check_;
    static std::atomic<bool> format_env_check_;
    static std::mutex severity_mutex_;
    static std::mutex format_mutex_;
#else
    static severity_type severity_level_;
    static bool severity_env_check_;
    static bool format_env_check_;
#endif
};


namespace detail {

// Default sink, it regulates access to clog

template<class Ch, class Tr, class A>
class clog_sink
{
public:
    using stream_buffer = std::basic_ostringstream<Ch, Tr, A>;

    void operator()(logger::severity_type const& /*severity*/, stream_buffer const& s)
    {
#ifdef MAPNIK_THREADSAFE
        static std::mutex mutex;
        std::lock_guard<std::mutex> lock(mutex);
#endif
        std::clog << logger::str() << " " << s.str() << std::endl;
    }
};

// Base log class, should not log anything when no MAPNIK_LOG is defined
//
// This is used for debug/warn reporting that should not output
// anything when not compiling for speed.

template<template <class Ch, class Tr, class A> class OutputPolicy,
         logger::severity_type Severity,
         class Ch = char,
         class Tr = std::char_traits<Ch>,
         class A = std::allocator<Ch> >
class base_log : public util::noncopyable
{
public:
    using output_policy = OutputPolicy<Ch, Tr, A>;

    base_log() {}

#ifdef MAPNIK_LOG
    base_log(const char* object_name)
    {
        if (object_name != nullptr)
        {
            object_name_ = object_name;
        }
    }
#else
    base_log(const char* /*object_name*/)
    {
    }
#endif

    ~base_log()
    {
#ifdef MAPNIK_LOG
        if (check_severity())
        {
            output_policy()(Severity, streambuf_);
        }
#endif
    }

    template<class T>
#ifdef MAPNIK_LOG
    base_log &operator<<(T const& x)
    {

        streambuf_ << x;
        return *this;
    }
#else
    base_log &operator<<(T const& /*x*/)
    {

        return *this;
    }
#endif

private:
#ifdef MAPNIK_LOG
    inline bool check_severity()
    {
        return Severity >= logger::get_object_severity(object_name_);
    }

    typename output_policy::stream_buffer streambuf_;
    std::string object_name_;
#endif
};



//Base log class that always log, regardless of MAPNIK_LOG.
//This is used for error reporting that should always log something

template<template <class Ch, class Tr, class A> class OutputPolicy,
         logger::severity_type Severity,
         class Ch = char,
         class Tr = std::char_traits<Ch>,
         class A = std::allocator<Ch> >
class base_log_always : public util::noncopyable
{
public:
    using output_policy = OutputPolicy<Ch, Tr, A>;

    base_log_always() {}

    base_log_always(const char* object_name)
    {
        if (object_name != nullptr)
        {
            object_name_ = object_name;
        }
    }

    ~base_log_always()
    {
        if (check_severity())
        {
            output_policy()(Severity, streambuf_);
        }
    }

    template<class T>
    base_log_always &operator<<(T const& x)
    {
        streambuf_ << x;
        return *this;
    }

private:
    inline bool check_severity()
    {
        return Severity >= logger::get_object_severity(object_name_);
    }

    typename output_policy::stream_buffer streambuf_;
    std::string object_name_;
};


using base_log_debug = base_log<clog_sink, logger::debug>;
using base_log_warn = base_log<clog_sink, logger::warn>;
using base_log_error = base_log_always<clog_sink, logger::error>;

} // namespace detail


// real interfaces
class MAPNIK_DECL warn : public detail::base_log_warn
{
public:
    warn() : detail::base_log_warn() {}
    warn(const char* object_name) : detail::base_log_warn(object_name) {}
};

class MAPNIK_DECL debug : public detail::base_log_debug
{
public:
    debug() : detail::base_log_debug() {}
    debug(const char* object_name) : detail::base_log_debug(object_name) {}
};

class MAPNIK_DECL error : public detail::base_log_error
{
public:
    error() : detail::base_log_error() {}
    error(const char* object_name) : detail::base_log_error(object_name) {}
};

// logging helpers
#define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s)
#define MAPNIK_LOG_WARN(s) mapnik::warn(#s)
#define MAPNIK_LOG_ERROR(s) mapnik::error(#s)
}

#endif // MAPNIK_DEBUG_HPP