• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #867

15 Jan 2023 08:00PM UTC coverage: 86.487% (+0.5%) from 85.951%
#867

push

StellarBot
Merge #6135

6135: Fixing warnings reported by MSVC analysis r=hkaiser a=hkaiser

- adding MSVC specific #pragma's to suppress the benign warnings


Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

120 of 120 new or added lines in 33 files covered. (100.0%)

174599 of 201880 relevant lines covered (86.49%)

1945607.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.78
/libs/core/init_runtime_local/src/init_logging.cpp
1
//  Copyright (c) 2007-2021 Hartmut Kaiser
2
//  Copyright (c)      2011 Bryce Lelbach
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/config.hpp>
9

10
#if defined(HPX_HAVE_LOGGING)
11
#include <hpx/init_runtime_local/detail/init_logging.hpp>
12
#include <hpx/runtime_configuration/runtime_configuration.hpp>
13
#include <hpx/runtime_local/get_locality_id.hpp>
14
#include <hpx/runtime_local/get_worker_thread_num.hpp>
15
#include <hpx/threading_base/thread_data.hpp>
16

17
#include <cstddef>
18
#include <cstdint>
19
#include <cstdlib>
20
#include <iostream>
21
#include <string>
22

23
#if defined(ANDROID) || defined(__ANDROID__)
24
#include <android/log.h>
25
#endif
26

27
///////////////////////////////////////////////////////////////////////////////
28
namespace hpx { namespace util {
29

30
    using logger_writer_type = logging::writer::named_write;
31

32
    ///////////////////////////////////////////////////////////////////////////
33
    // custom formatter: shepherd
34
    struct shepherd_thread_id : logging::formatter::manipulator
12,230✔
35
    {
36
        void operator()(std::ostream& to) const override
×
37
        {
38
            error_code ec(throwmode::lightweight);
×
39
            std::size_t thread_num = hpx::get_worker_thread_num(ec);
×
40

41
            if (std::size_t(-1) != thread_num)
×
42
            {
43
                util::format_to(to, "{:016x}", thread_num);
×
44
            }
×
45
            else
46
            {
47
                to << std::string(16, '-');
×
48
            }
49
        }
×
50
    };
51

52
    ///////////////////////////////////////////////////////////////////////////
53
    // custom formatter: locality prefix
54
    struct locality_prefix : logging::formatter::manipulator
12,230✔
55
    {
56
        void operator()(std::ostream& to) const override
56,595,296✔
57
        {
58
            std::uint32_t locality_id = hpx::get_locality_id();
56,505,658✔
59

60
            if (~static_cast<std::uint32_t>(0) != locality_id)
56,505,658✔
61
            {
62
                util::format_to(to, "{:08x}", locality_id);
55,870,617✔
63
            }
55,870,617✔
64
            else
65
            {
66
                // called from outside a HPX thread
67
                to << std::string(8, '-');
606,620✔
68
            }
69
        }
56,477,237✔
70
    };
71

72
    ///////////////////////////////////////////////////////////////////////////
73
    // custom formatter: HPX thread id
74
    struct thread_id : logging::formatter::manipulator
12,230✔
75
    {
76
        void operator()(std::ostream& to) const override
56,532,708✔
77
        {
78
            threads::thread_self* self = threads::get_self_ptr();
56,540,799✔
79
            if (nullptr != self)
56,540,799✔
80
            {
81
                // called from inside a HPX thread
82
                threads::thread_id_type id = threads::get_self_id();
13,464,605✔
83
                if (id != threads::invalid_thread_id)
13,464,605✔
84
                {
85
                    std::ptrdiff_t value =
13,464,424✔
86
                        reinterpret_cast<std::ptrdiff_t>(id.get());
13,464,424✔
87
                    util::format_to(to, "{:016x}", value);
13,464,424✔
88
                    return;
13,464,424✔
89
                }
90
            }
×
91

92
            // called from outside a HPX thread or invalid thread id
93
            to << std::string(16, '-');
43,074,647✔
94
        }
56,613,502✔
95
    };
96

97
    ///////////////////////////////////////////////////////////////////////////
98
    // custom formatter: HPX thread phase
99
    struct thread_phase : logging::formatter::manipulator
12,230✔
100
    {
101
        void operator()(std::ostream& to) const override
56,565,613✔
102
        {
103
            threads::thread_self* self = threads::get_self_ptr();
56,564,819✔
104
            if (nullptr != self)
56,564,819✔
105
            {
106
                // called from inside a HPX thread
107
                std::size_t phase = self->get_thread_phase();
13,464,510✔
108
                if (0 != phase)
13,464,510✔
109
                {
110
                    util::format_to(to, "{:04x}", self->get_thread_phase());
×
111
                    return;
×
112
                }
113
            }
13,464,527✔
114

115
            // called from outside a HPX thread or no phase given
116
            to << std::string(4, '-');    //-V112
56,564,345✔
117
        }
56,567,931✔
118
    };
119

120
    ///////////////////////////////////////////////////////////////////////////
121
    // custom formatter: locality prefix of parent thread
122
    struct parent_thread_locality : logging::formatter::manipulator
12,230✔
123
    {
124
        void operator()(std::ostream& to) const override
56,574,813✔
125
        {
126
            std::uint32_t parent_locality_id =
56,570,062✔
127
                threads::get_parent_locality_id();
56,570,062✔
128
            if (~static_cast<std::uint32_t>(0) != parent_locality_id)
56,570,062✔
129
            {
130
                // called from inside a HPX thread
131
                util::format_to(to, "{:08x}", parent_locality_id);
×
132
            }
×
133
            else
134
            {
135
                // called from outside a HPX thread
136
                to << std::string(8, '-');
56,570,062✔
137
            }
138
        }
56,590,916✔
139
    };
140

141
    ///////////////////////////////////////////////////////////////////////////
142
    // custom formatter: HPX parent thread id
143
    struct parent_thread_id : logging::formatter::manipulator
12,230✔
144
    {
145
        void operator()(std::ostream& to) const override
56,571,959✔
146
        {
147
            threads::thread_id_type parent_id = threads::get_parent_id();
56,568,327✔
148
            if (nullptr != parent_id)
56,568,327✔
149
            {
150
                // called from inside a HPX thread
151
                std::ptrdiff_t value =
×
152
                    reinterpret_cast<std::ptrdiff_t>(parent_id.get());
×
153
                util::format_to(to, "{:016x}", value);
×
154
            }
×
155
            else
156
            {
157
                // called from outside a HPX thread
158
                to << std::string(16, '-');
56,568,327✔
159
            }
160
        }
56,599,644✔
161
    };
162

163
    ///////////////////////////////////////////////////////////////////////////
164
    // custom formatter: HPX parent thread phase
165
    struct parent_thread_phase : logging::formatter::manipulator
12,230✔
166
    {
167
        void operator()(std::ostream& to) const override
56,588,436✔
168
        {
169
            std::size_t parent_phase = threads::get_parent_phase();
56,583,184✔
170
            if (0 != parent_phase)
56,583,184✔
171
            {
172
                // called from inside a HPX thread
173
                util::format_to(to, "{:04x}", parent_phase);
×
174
            }
×
175
            else
176
            {
177
                // called from outside a HPX thread
178
                to << std::string(4, '-');    //-V112
56,583,184✔
179
            }
180
        }
56,596,671✔
181
    };
182

183
#if defined(ANDROID) || defined(__ANDROID__)
184
    // default log destination for Android
185
    struct android_log : logging::destination::manipulator
186
    {
187
        android_log(char const* tag_)
188
          : tag(tag_)
189
        {
190
        }
191

192
        void operator()(logging::message const& msg) override
193
        {
194
            __android_log_write(
195
                ANDROID_LOG_DEBUG, tag.c_str(), msg.full_string().c_str());
196
        }
197

198
        bool operator==(android_log const& rhs) const
199
        {
200
            return tag == rhs.tag;
201
        }
202

203
        std::string tag;
204
    };
205
#endif
206

207
    ///////////////////////////////////////////////////////////////////////////
208
    struct dummy_thread_component_id : logging::formatter::manipulator
6,250✔
209
    {
210
        void operator()(std::ostream& to) const override
24,786,978✔
211
        {
212
            to << std::string(16, '-');
24,786,978✔
213
        }
24,815,670✔
214
    };
215

216
    ///////////////////////////////////////////////////////////////////////////
217
    // custom log destination: send generated strings to console
218
    void console_local::operator()(logging::message const& msg)
×
219
    {
220
        switch (dest_)
×
221
        {
×
222
        default:
223
        case logging_destination::hpx:
224
            LHPX_CONSOLE_(level_) << msg;
×
225
            break;
×
226

227
        case logging_destination::timing:
228
            LTIM_CONSOLE_(level_) << msg;
×
229
            break;
×
230

231
        case logging_destination::agas:
232
            LAGAS_CONSOLE_(level_) << msg;
×
233
            break;
×
234

235
        case logging_destination::parcel:
236
            LPT_CONSOLE_(level_) << msg;
×
237
            break;
×
238

239
        case logging_destination::app:
240
            LAPP_CONSOLE_(level_) << msg;
×
241
            break;
×
242

243
        case logging_destination::debuglog:
244
            LDEB_CONSOLE_ << msg;
×
245
            break;
×
246
        }
247
    }
×
248

249
    namespace detail {
250

251
        // unescape config entry
252
        std::string unescape(std::string const& value)
14,676✔
253
        {
254
            std::string result;
14,676✔
255
            std::string::size_type pos = 0;
14,676✔
256
            std::string::size_type pos1 = value.find_first_of('\\', 0);
14,676✔
257
            if (std::string::npos != pos1)
14,676✔
258
            {
259
                do
7,338✔
260
                {
261
                    switch (value[pos1 + 1])
7,338✔
262
                    {
263
                    case '\\':
264
                    case '\"':
265
                    case '?':
266
                        result = result + value.substr(pos, pos1 - pos);
×
267
                        pos1 = value.find_first_of('\\', (pos = pos1 + 1) + 1);
×
268
                        break;
×
269

270
                    case 'n':
271
                        result = result + value.substr(pos, pos1 - pos) + "\n";
7,338✔
272
                        pos1 = value.find_first_of('\\', pos = pos1 + 1);
7,338✔
273
                        ++pos;
7,338✔
274
                        break;
7,338✔
275

276
                    default:
277
                        result = result + value.substr(pos, pos1 - pos + 1);
×
278
                        pos1 = value.find_first_of('\\', pos = pos1 + 1);
×
279
                    }
×
280

281
                } while (pos1 != std::string::npos);
7,338✔
282
                result = result + value.substr(pos);
7,338✔
283
            }
7,338✔
284
            else
285
            {
286
                // the string doesn't contain any escaped character sequences
287
                result = value;
7,338✔
288
            }
289
            return result;
14,676✔
290
        }
14,676✔
291

292
        void define_common_formatters(logger_writer_type& writer)
2,446✔
293
        {
294
            writer.set_formatter("osthread", shepherd_thread_id());
2,446✔
295
            writer.set_formatter("locality", locality_prefix());
2,446✔
296
            writer.set_formatter("hpxthread", thread_id());
2,446✔
297
            writer.set_formatter("hpxphase", thread_phase());
2,446✔
298
            writer.set_formatter("hpxparent", parent_thread_id());
2,446✔
299
            writer.set_formatter("hpxparentphase", parent_thread_phase());
2,446✔
300
            writer.set_formatter("parentloc", parent_thread_locality());
2,446✔
301
        }
2,446✔
302

303
        void define_formatters_local(logger_writer_type& writer)
1,250✔
304
        {
305
            define_common_formatters(writer);
1,250✔
306
            writer.set_formatter("hpxcomponent", dummy_thread_component_id());
1,250✔
307
        }
1,250✔
308

309
        ///////////////////////////////////////////////////////////////////////
310
        static std::string empty_string;
1,253✔
311

312
        log_settings get_log_settings(util::section const& ini, char const* sec)
14,676✔
313
        {
314
            log_settings result;
14,676✔
315
            if (ini.has_section(sec))
14,676✔
316
            {
317
                util::section const* logini = ini.get_section(sec);
14,676✔
318
                HPX_ASSERT(nullptr != logini);
14,676✔
319

320
                result.level_ = logini ?
29,352✔
321
                    logini->get_entry("level", empty_string) :
14,676✔
322
                    empty_string;
×
323
                if (logini && !result.level_.empty())
14,676✔
324
                {
325
                    result.dest_ =
14,676✔
326
                        logini->get_entry("destination", empty_string);
14,676✔
327
                    result.format_ = detail::unescape(
14,676✔
328
                        logini->get_entry("format", empty_string));
14,676✔
329
                }
14,676✔
330
            }
14,676✔
331
            return result;
14,676✔
332
        }
14,676✔
333

334
        ///////////////////////////////////////////////////////////////////////
335
        void get_console_local(logger_writer_type& writer, char const* name,
1,250✔
336
            logging::level lvl, logging_destination dest)
337
        {
338
            writer.set_destination(name, console_local(lvl, dest));
1,250✔
339
        }
1,250✔
340

341
        ///////////////////////////////////////////////////////////////////////
342
        // initialize logging for AGAS
343
        void init_agas_log(logging::level lvl, std::string logdest,
1,223✔
344
            std::string logformat, bool isconsole,
345
            void (*set_console_dest)(logger_writer_type&, char const*,
346
                logging::level, logging_destination),
347
            void (*define_formatters)(logging::writer::named_write&))
348
        {
349
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
350
            {
351
                logger_writer_type& writer = agas_logger()->writer();
×
352

353
#if defined(ANDROID) || defined(__ANDROID__)
354
                if (logdest.empty())    // ensure minimal defaults
355
                    logdest = isconsole ? "android_log" : "console";
356
                agas_logger()->writer().set_destination(
357
                    "android_log", android_log("hpx.agas"));
358
#else
359
                if (logdest.empty())    // ensure minimal defaults
×
360
                    logdest = isconsole ? "cerr" : "console";
×
361
#endif
362
                if (logformat.empty())
×
363
                    logformat = "|\\n";
×
364

365
                set_console_dest(writer, "console", lvl,
×
366
                    logging_destination::agas);    //-V106
367
                writer.write(logformat, logdest);
×
368
                define_formatters(writer);
×
369

370
                agas_logger()->mark_as_initialized();
×
371
            }
×
372
            agas_logger()->set_enabled(lvl);
1,223✔
373
        }
1,223✔
374

375
        void init_agas_log(runtime_configuration& ini, bool isconsole,
1,223✔
376
            void (*set_console_dest)(logger_writer_type&, char const*,
377
                logging::level, logging_destination),
378
            void (*define_formatters)(logging::writer::named_write&))
379
        {
380
            auto settings = detail::get_log_settings(ini, "hpx.logging.agas");
1,223✔
381

382
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
383
            if (!settings.level_.empty())
1,223✔
384
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
385

386
            init_agas_log(lvl, HPX_MOVE(settings.dest_),
2,446✔
387
                HPX_MOVE(settings.format_), isconsole, set_console_dest,
1,223✔
388
                define_formatters);
1,223✔
389
        }
1,223✔
390

391
        ///////////////////////////////////////////////////////////////////////
392
        // initialize logging for the parcel transport
393
        void init_parcel_log(logging::level lvl, std::string logdest,
1,223✔
394
            std::string logformat, bool isconsole,
395
            void (*set_console_dest)(logger_writer_type&, char const*,
396
                logging::level, logging_destination),
397
            void (*define_formatters)(logging::writer::named_write&))
398
        {
399
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
400
            {
401
                logger_writer_type& writer = parcel_logger()->writer();
×
402

403
#if defined(ANDROID) || defined(__ANDROID__)
404
                if (logdest.empty())    // ensure minimal defaults
405
                    logdest = isconsole ? "android_log" : "console";
406
                parcel_logger()->writer().set_destination(
407
                    "android_log", android_log("hpx.parcel"));
408
#else
409
                if (logdest.empty())    // ensure minimal defaults
×
410
                    logdest = isconsole ? "cerr" : "console";
×
411
#endif
412
                if (logformat.empty())
×
413
                    logformat = "|\\n";
×
414

415
                set_console_dest(writer, "console", lvl,
×
416
                    logging_destination::parcel);    //-V106
417
                writer.write(logformat, logdest);
×
418
                define_formatters(writer);
×
419

420
                parcel_logger()->mark_as_initialized();
×
421
            }
×
422
            parcel_logger()->set_enabled(lvl);
1,223✔
423
        }
1,223✔
424

425
        void init_parcel_log(runtime_configuration& ini, bool isconsole,
1,223✔
426
            void (*set_console_dest)(logger_writer_type&, char const*,
427
                logging::level, logging_destination),
428
            void (*define_formatters)(logging::writer::named_write&))
429
        {
430
            auto settings = detail::get_log_settings(ini, "hpx.logging.parcel");
1,223✔
431

432
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
433
            if (!settings.level_.empty())
1,223✔
434
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
435

436
            init_parcel_log(lvl, HPX_MOVE(settings.dest_),
2,446✔
437
                HPX_MOVE(settings.format_), isconsole, set_console_dest,
1,223✔
438
                define_formatters);
1,223✔
439
        }
1,223✔
440

441
        ///////////////////////////////////////////////////////////////////////
442
        // initialize logging for performance measurements
443
        void init_timing_log(logging::level lvl, std::string logdest,
1,223✔
444
            std::string logformat, bool isconsole,
445
            void (*set_console_dest)(logger_writer_type&, char const*,
446
                logging::level, logging_destination),
447
            void (*define_formatters)(logging::writer::named_write&))
448
        {
449
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
450
            {
451
                logger_writer_type& writer = timing_logger()->writer();
×
452

453
#if defined(ANDROID) || defined(__ANDROID__)
454
                if (logdest.empty())    // ensure minimal defaults
455
                    logdest = isconsole ? "android_log" : "console";
456

457
                writer.set_destination(
458
                    "android_log", android_log("hpx.timing"));
459
#else
460
                if (logdest.empty())    // ensure minimal defaults
×
461
                    logdest = isconsole ? "cerr" : "console";
×
462
#endif
463
                if (logformat.empty())
×
464
                    logformat = "|\\n";
×
465

466
                set_console_dest(writer, "console", lvl,
×
467
                    logging_destination::timing);    //-V106
468
                writer.write(logformat, logdest);
×
469
                define_formatters(writer);
×
470

471
                timing_logger()->mark_as_initialized();
×
472
            }
×
473
            timing_logger()->set_enabled(lvl);
1,223✔
474
        }
1,223✔
475

476
        void init_timing_log(runtime_configuration& ini, bool isconsole,
1,223✔
477
            void (*set_console_dest)(logger_writer_type&, char const*,
478
                logging::level, logging_destination),
479
            void (*define_formatters)(logging::writer::named_write&))
480
        {
481
            auto settings = detail::get_log_settings(ini, "hpx.logging.timing");
1,223✔
482

483
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
484
            if (!settings.level_.empty())
1,223✔
485
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
486

487
            init_timing_log(lvl, HPX_MOVE(settings.dest_),
2,446✔
488
                HPX_MOVE(settings.format_), isconsole, set_console_dest,
1,223✔
489
                define_formatters);
1,223✔
490
        }
1,223✔
491

492
        ///////////////////////////////////////////////////////////////////////
493
        void init_hpx_log(logging::level lvl, std::string logdest,
1,223✔
494
            std::string logformat, bool isconsole,
495
            void (*set_console_dest)(logger_writer_type&, char const*,
496
                logging::level, logging_destination),
497
            void (*define_formatters)(logging::writer::named_write&))
498
        {
499
            logger_writer_type& writer = hpx_logger()->writer();
1,223✔
500
            logger_writer_type& error_writer = hpx_error_logger()->writer();
1,223✔
501

502
#if defined(ANDROID) || defined(__ANDROID__)
503
            if (logdest.empty())    // ensure minimal defaults
504
                logdest = isconsole ? "android_log" : "console";
505

506
            writer.set_destination("android_log", android_log("hpx"));
507
            error_writer.set_destination("android_log", android_log("hpx"));
508
#else
509
            if (logdest.empty())    // ensure minimal defaults
1,223✔
510
                logdest = isconsole ? "cerr" : "console";
×
511
#endif
512
            if (logformat.empty())
1,223✔
513
                logformat = "|\\n";
×
514

515
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
516
            {
517
                set_console_dest(writer, "console", lvl,
1,223✔
518
                    logging_destination::hpx);    //-V106
519
                writer.write(logformat, logdest);
1,223✔
520
                define_formatters(writer);
1,223✔
521

522
                hpx_logger()->mark_as_initialized();
1,223✔
523
                hpx_logger()->set_enabled(lvl);
1,223✔
524

525
                // errors are logged to the given destination and to cerr
526
                set_console_dest(error_writer, "console", lvl,
1,223✔
527
                    logging_destination::hpx);    //-V106
528
#if !defined(ANDROID) && !defined(__ANDROID__)
529
                if (logdest != "cerr")
1,223✔
530
                    error_writer.write(logformat, logdest + " cerr");
1,223✔
531
#endif
532
                define_formatters(error_writer);
1,223✔
533

534
                hpx_error_logger()->mark_as_initialized();
1,223✔
535
                hpx_error_logger()->set_enabled(lvl);
1,223✔
536
            }
1,223✔
537
            else
538
            {
539
                // errors are always logged to cerr
540
                if (!isconsole)
×
541
                {
542
                    set_console_dest(writer, "console", lvl,
×
543
                        logging_destination::hpx);    //-V106
544
                    error_writer.write(logformat, "console");
×
545
                }
×
546
                else
547
                {
548
#if defined(ANDROID) || defined(__ANDROID__)
549
                    error_writer.write(logformat, "android_log");
550
#else
551
                    error_writer.write(logformat, "cerr");
×
552
#endif
553
                }
554
                define_formatters(error_writer);
×
555

556
                hpx_error_logger()->mark_as_initialized();
×
557
                hpx_error_logger()->set_enabled(
×
558
                    hpx::util::logging::level::fatal);
559
            }
560
        }
1,223✔
561

562
        void init_hpx_log(runtime_configuration& ini, bool isconsole,
1,223✔
563
            void (*set_console_dest)(logger_writer_type&, char const*,
564
                logging::level, logging_destination),
565
            void (*define_formatters)(logging::writer::named_write&))
566
        {
567
            auto settings = detail::get_log_settings(ini, "hpx.logging");
1,223✔
568

569
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
570
            if (!settings.level_.empty())
1,223✔
571
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
572

573
            init_hpx_log(lvl, HPX_MOVE(settings.dest_),
2,446✔
574
                HPX_MOVE(settings.format_), isconsole, set_console_dest,
1,223✔
575
                define_formatters);
1,223✔
576
        }
1,223✔
577

578
        ///////////////////////////////////////////////////////////////////////
579
        // initialize logging for application
580
        void init_app_log(logging::level lvl, std::string logdest,
1,223✔
581
            std::string logformat, bool isconsole,
582
            void (*set_console_dest)(logger_writer_type&, char const*,
583
                logging::level, logging_destination),
584
            void (*define_formatters)(logging::writer::named_write&))
585
        {
586
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
587
            {
588
                logger_writer_type& writer = app_logger()->writer();
×
589

590
#if defined(ANDROID) || defined(__ANDROID__)
591
                if (logdest.empty())    // ensure minimal defaults
592
                    logdest = isconsole ? "android_log" : "console";
593
                writer.set_destination(
594
                    "android_log", android_log("hpx.application"));
595
#else
596
                if (logdest.empty())    // ensure minimal defaults
×
597
                    logdest = isconsole ? "cerr" : "console";
×
598
#endif
599
                if (logformat.empty())
×
600
                    logformat = "|\\n";
×
601

602
                set_console_dest(writer, "console", lvl,
×
603
                    logging_destination::app);    //-V106
604
                writer.write(logformat, logdest);
×
605
                define_formatters(writer);
×
606

607
                app_logger()->mark_as_initialized();
×
608
            }
×
609
            app_logger()->set_enabled(lvl);
1,223✔
610
        }
1,223✔
611

612
        void init_app_log(runtime_configuration& ini, bool isconsole,
1,223✔
613
            void (*set_console_dest)(logger_writer_type&, char const*,
614
                logging::level, logging_destination),
615
            void (*define_formatters)(logging::writer::named_write&))
616
        {
617
            auto settings =
618
                detail::get_log_settings(ini, "hpx.logging.application");
1,223✔
619

620
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
621
            if (!settings.level_.empty())
1,223✔
622
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
623

624
            init_app_log(lvl, HPX_MOVE(settings.dest_),
2,446✔
625
                HPX_MOVE(settings.format_), isconsole, set_console_dest,
1,223✔
626
                define_formatters);
1,223✔
627
        }
1,223✔
628

629
        ///////////////////////////////////////////////////////////////////////
630
        // initialize logging for application
631
        void init_debuglog_log(logging::level lvl, std::string logdest,
1,223✔
632
            std::string logformat, bool isconsole,
633
            void (*set_console_dest)(logger_writer_type&, char const*,
634
                logging::level, logging_destination),
635
            void (*define_formatters)(logging::writer::named_write&))
636
        {
637
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
638
            {
639
                logger_writer_type& writer = debuglog_logger()->writer();
×
640

641
#if defined(ANDROID) || defined(__ANDROID__)
642
                if (logdest.empty())    // ensure minimal defaults
643
                    logdest = isconsole ? "android_log" : "console";
644
                writer.set_destination(
645
                    "android_log", android_log("hpx.debuglog"));
646
#else
647
                if (logdest.empty())    // ensure minimal defaults
×
648
                    logdest = isconsole ? "cerr" : "console";
×
649
#endif
650
                if (logformat.empty())
×
651
                    logformat = "|\\n";
×
652

653
                set_console_dest(writer, "console", lvl,
×
654
                    logging_destination::debuglog);    //-V106
655
                writer.write(logformat, logdest);
×
656
                define_formatters(writer);
×
657

658
                debuglog_logger()->mark_as_initialized();
×
659
            }
×
660
            debuglog_logger()->set_enabled(lvl);
1,223✔
661
        }
1,223✔
662

663
        void init_debuglog_log(runtime_configuration& ini, bool isconsole,
1,223✔
664
            void (*set_console_dest)(logger_writer_type&, char const*,
665
                logging::level, logging_destination),
666
            void (*define_formatters)(logging::writer::named_write&))
667
        {
668
            auto settings =
669
                detail::get_log_settings(ini, "hpx.logging.debuglog");
1,223✔
670

671
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
672
            if (!settings.level_.empty())
1,223✔
673
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
674

675
            init_debuglog_log(lvl, HPX_MOVE(settings.dest_),
2,446✔
676
                HPX_MOVE(settings.format_), isconsole, set_console_dest,
1,223✔
677
                define_formatters);
1,223✔
678
        }
1,223✔
679

680
        ///////////////////////////////////////////////////////////////////////
681
        void init_agas_console_log(
1,223✔
682
            logging::level lvl, std::string logdest, std::string logformat)
683
        {
684
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
685
            {
686
                logger_writer_type& writer = agas_console_logger()->writer();
×
687

688
#if defined(ANDROID) || defined(__ANDROID__)
689
                if (logdest.empty())    // ensure minimal defaults
690
                    logdest = "android_log";
691
                writer.set_destination("android_log", android_log("hpx.agas"));
692
#else
693
                if (logdest.empty())    // ensure minimal defaults
×
694
                    logdest = "cerr";
×
695
#endif
696
                if (logformat.empty())
×
697
                    logformat = "|\\n";
×
698

699
                writer.write(logformat, logdest);
×
700

701
                agas_console_logger()->mark_as_initialized();
×
702
            }
×
703
            agas_console_logger()->set_enabled(lvl);
1,223✔
704
        }
1,223✔
705

706
        void init_agas_console_log(util::section const& ini)
1,223✔
707
        {
708
            auto settings =
709
                detail::get_log_settings(ini, "hpx.logging.console.agas");
1,223✔
710

711
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
712
            if (!settings.level_.empty())
1,223✔
713
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
714

715
            init_agas_console_log(
1,223✔
716
                lvl, HPX_MOVE(settings.dest_), HPX_MOVE(settings.format_));
1,223✔
717
        }
1,223✔
718

719
        ///////////////////////////////////////////////////////////////////////
720
        void init_parcel_console_log(
1,223✔
721
            logging::level lvl, std::string logdest, std::string logformat)
722
        {
723
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
724
            {
725
                logger_writer_type& writer = parcel_console_logger()->writer();
×
726

727
#if defined(ANDROID) || defined(__ANDROID__)
728
                if (logdest.empty())    // ensure minimal defaults
729
                    logdest = "android_log";
730
                writer.set_destination(
731
                    "android_log", android_log("hpx.parcel"));
732
#else
733
                if (logdest.empty())    // ensure minimal defaults
×
734
                    logdest = "cerr";
×
735
#endif
736
                if (logformat.empty())
×
737
                    logformat = "|\\n";
×
738

739
                writer.write(logformat, logdest);
×
740

741
                parcel_console_logger()->mark_as_initialized();
×
742
            }
×
743
            parcel_console_logger()->set_enabled(lvl);
1,223✔
744
        }
1,223✔
745

746
        void init_parcel_console_log(util::section const& ini)
1,223✔
747
        {
748
            auto settings =
749
                detail::get_log_settings(ini, "hpx.logging.console.parcel");
1,223✔
750

751
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
752
            if (!settings.level_.empty())
1,223✔
753
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
754

755
            init_parcel_console_log(
1,223✔
756
                lvl, HPX_MOVE(settings.dest_), HPX_MOVE(settings.format_));
1,223✔
757
        }
1,223✔
758

759
        ///////////////////////////////////////////////////////////////////////
760
        void init_timing_console_log(
1,223✔
761
            logging::level lvl, std::string logdest, std::string logformat)
762
        {
763
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
764
            {
765
                logger_writer_type& writer = timing_console_logger()->writer();
×
766

767
#if defined(ANDROID) || defined(__ANDROID__)
768
                if (logdest.empty())    // ensure minimal defaults
769
                    logdest = "android_log";
770
                writer.set_destination(
771
                    "android_log", android_log("hpx.timing"));
772
#else
773
                if (logdest.empty())    // ensure minimal defaults
×
774
                    logdest = "cerr";
×
775
#endif
776
                if (logformat.empty())
×
777
                    logformat = "|\\n";
×
778

779
                writer.write(logformat, logdest);
×
780

781
                timing_console_logger()->mark_as_initialized();
×
782
            }
×
783
            timing_console_logger()->set_enabled(lvl);
1,223✔
784
        }
1,223✔
785

786
        void init_timing_console_log(util::section const& ini)
1,223✔
787
        {
788
            auto settings =
789
                detail::get_log_settings(ini, "hpx.logging.console.timing");
1,223✔
790

791
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
792
            if (!settings.level_.empty())
1,223✔
793
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
794

795
            init_timing_console_log(
1,223✔
796
                lvl, HPX_MOVE(settings.dest_), HPX_MOVE(settings.format_));
1,223✔
797
        }
1,223✔
798

799
        ///////////////////////////////////////////////////////////////////////
800
        void init_hpx_console_log(
1,223✔
801
            logging::level lvl, std::string logdest, std::string logformat)
802
        {
803
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
804
            {
805
                logger_writer_type& writer = hpx_console_logger()->writer();
1,223✔
806

807
#if defined(ANDROID) || defined(__ANDROID__)
808
                if (logdest.empty())    // ensure minimal defaults
809
                    logdest = "android_log";
810
                writer.set_destination("android_log", android_log("hpx"));
811
#else
812
                if (logdest.empty())    // ensure minimal defaults
1,223✔
813
                    logdest = "cerr";
×
814
#endif
815
                if (logformat.empty())
1,223✔
816
                    logformat = "|\\n";
×
817

818
                writer.write(logformat, logdest);
1,223✔
819

820
                hpx_console_logger()->mark_as_initialized();
1,223✔
821
            }
1,223✔
822
            hpx_console_logger()->set_enabled(lvl);
1,223✔
823
        }
1,223✔
824

825
        void init_hpx_console_log(util::section const& ini)
1,223✔
826
        {
827
            auto settings =
828
                detail::get_log_settings(ini, "hpx.logging.console");
1,223✔
829

830
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
831
            if (!settings.level_.empty())
1,223✔
832
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
833

834
            init_hpx_console_log(
1,223✔
835
                lvl, HPX_MOVE(settings.dest_), HPX_MOVE(settings.format_));
1,223✔
836
        }
1,223✔
837

838
        ///////////////////////////////////////////////////////////////////////
839
        void init_app_console_log(
1,223✔
840
            logging::level lvl, std::string logdest, std::string logformat)
841
        {
842
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
843
            {
844
                logger_writer_type& writer = app_console_logger()->writer();
×
845

846
#if defined(ANDROID) || defined(__ANDROID__)
847
                if (logdest.empty())    // ensure minimal defaults
848
                    logdest = "android_log";
849
                writer.set_destination(
850
                    "android_log", android_log("hpx.application"));
851
#else
852
                if (logdest.empty())    // ensure minimal defaults
×
853
                    logdest = "cerr";
×
854
#endif
855
                if (logformat.empty())
×
856
                    logformat = "|\\n";
×
857

858
                writer.write(logformat, logdest);
×
859

860
                app_console_logger()->mark_as_initialized();
×
861
            }
×
862
            app_console_logger()->set_enabled(lvl);
1,223✔
863
        }
1,223✔
864

865
        void init_app_console_log(util::section const& ini)
1,223✔
866
        {
867
            auto settings = detail::get_log_settings(
1,223✔
868
                ini, "hpx.logging.console.application");
1,223✔
869

870
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
871
            if (!settings.level_.empty())
1,223✔
872
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
873

874
            init_app_console_log(
1,223✔
875
                lvl, HPX_MOVE(settings.dest_), HPX_MOVE(settings.format_));
1,223✔
876
        }
1,223✔
877

878
        ///////////////////////////////////////////////////////////////////////
879
        void init_debuglog_console_log(
1,223✔
880
            logging::level lvl, std::string logdest, std::string logformat)
881
        {
882
            if (hpx::util::logging::level::disable_all != lvl)
1,223✔
883
            {
884
                logger_writer_type& writer =
×
885
                    debuglog_console_logger()->writer();
×
886

887
#if defined(ANDROID) || defined(__ANDROID__)
888
                if (logdest.empty())    // ensure minimal defaults
889
                    logdest = "android_log";
890
                writer.set_destination(
891
                    "android_log", android_log("hpx.debuglog"));
892
#else
893
                if (logdest.empty())    // ensure minimal defaults
×
894
                    logdest = "cerr";
×
895
#endif
896
                if (logformat.empty())
×
897
                    logformat = "|\\n";
×
898

899
                writer.write(logformat, logdest);
×
900

901
                debuglog_console_logger()->mark_as_initialized();
×
902
            }
×
903
            debuglog_console_logger()->set_enabled(lvl);
1,223✔
904
        }
1,223✔
905

906
        void init_debuglog_console_log(util::section const& ini)
1,223✔
907
        {
908
            auto settings =
909
                detail::get_log_settings(ini, "hpx.logging.console.debuglog");
1,223✔
910

911
            auto lvl = hpx::util::logging::level::disable_all;
1,223✔
912
            if (!settings.level_.empty())
1,223✔
913
                lvl = detail::get_log_level(settings.level_, true);
1,223✔
914

915
            init_debuglog_console_log(
1,223✔
916
                lvl, HPX_MOVE(settings.dest_), HPX_MOVE(settings.format_));
1,223✔
917
        }
1,223✔
918

919
        ///////////////////////////////////////////////////////////////////////
920
        static void (*default_set_console_dest)(logger_writer_type&,
921
            char const*, logging::level,
922
            logging_destination) = get_console_local;
923

924
        static void (*default_define_formatters)(
925
            logging::writer::named_write&) = define_formatters_local;
926

927
        static bool default_isconsole = true;
928

929
        void init_logging(runtime_configuration& ini, bool isconsole,
1,223✔
930
            void (*set_console_dest)(logger_writer_type&, char const*,
931
                logging::level, logging_destination),
932
            void (*define_formatters)(logging::writer::named_write&))
933
        {
934
            default_isconsole = isconsole;
1,223✔
935
            default_set_console_dest = set_console_dest;
1,223✔
936
            default_define_formatters = define_formatters;
1,223✔
937

938
            // initialize normal logs
939
            init_agas_log(ini, isconsole, set_console_dest, define_formatters);
1,223✔
940
            init_parcel_log(
1,223✔
941
                ini, isconsole, set_console_dest, define_formatters);
1,223✔
942
            init_timing_log(
1,223✔
943
                ini, isconsole, set_console_dest, define_formatters);
1,223✔
944
            init_hpx_log(ini, isconsole, set_console_dest, define_formatters);
1,223✔
945
            init_app_log(ini, isconsole, set_console_dest, define_formatters);
1,223✔
946
            init_debuglog_log(
1,223✔
947
                ini, isconsole, set_console_dest, define_formatters);
1,223✔
948

949
            // initialize console logs
950
            init_agas_console_log(ini);
1,223✔
951
            init_parcel_console_log(ini);
1,223✔
952
            init_timing_console_log(ini);
1,223✔
953
            init_hpx_console_log(ini);
1,223✔
954
            init_app_console_log(ini);
1,223✔
955
            init_debuglog_console_log(ini);
1,223✔
956
        }
1,223✔
957

958
        void init_logging_local(runtime_configuration& ini)
625✔
959
        {
960
            init_logging(ini, true, util::detail::get_console_local,
625✔
961
                util::detail::define_formatters_local);
962
        }
625✔
963
    }    // namespace detail
964

965
    ///////////////////////////////////////////////////////////////////////////
966
    void disable_logging(logging_destination dest)
×
967
    {
968
        switch (dest)
×
969
        {
970
        case logging_destination::hpx:
971
            hpx_logger()->set_enabled(logging::level::disable_all);
×
972
            hpx_console_logger()->set_enabled(logging::level::disable_all);
×
973
            break;
×
974

975
        case logging_destination::timing:
976
            timing_logger()->set_enabled(logging::level::disable_all);
×
977
            timing_console_logger()->set_enabled(logging::level::disable_all);
×
978
            break;
×
979

980
        case logging_destination::agas:
981
            agas_logger()->set_enabled(logging::level::disable_all);
×
982
            agas_console_logger()->set_enabled(logging::level::disable_all);
×
983
            break;
×
984

985
        case logging_destination::parcel:
986
            parcel_logger()->set_enabled(logging::level::disable_all);
×
987
            parcel_console_logger()->set_enabled(logging::level::disable_all);
×
988
            break;
×
989

990
        case logging_destination::app:
991
            app_logger()->set_enabled(logging::level::disable_all);
×
992
            app_console_logger()->set_enabled(logging::level::disable_all);
×
993
            break;
×
994

995
        case logging_destination::debuglog:
996
            debuglog_logger()->set_enabled(logging::level::disable_all);
×
997
            debuglog_console_logger()->set_enabled(logging::level::disable_all);
×
998
            break;
×
999
        }
1000
    }
×
1001

1002
    void enable_logging(logging_destination dest, std::string const& level,
×
1003
        std::string logdest, std::string logformat)
1004
    {
1005
        auto lvl = hpx::util::logging::level::enable_all;
×
1006
        if (!level.empty())
×
1007
        {
1008
            lvl = detail::get_log_level(level, true);
×
1009
        }
×
1010

1011
        switch (dest)
×
1012
        {
1013
        case logging_destination::hpx:
1014
            detail::init_hpx_log(lvl, logdest, logformat,
×
1015
                detail::default_isconsole, detail::default_set_console_dest,
×
1016
                detail::default_define_formatters);
×
1017
            detail::init_hpx_console_log(
×
1018
                lvl, HPX_MOVE(logdest), HPX_MOVE(logformat));
×
1019
            break;
×
1020

1021
        case logging_destination::timing:
1022
            detail::init_timing_log(lvl, logdest, logformat,
×
1023
                detail::default_isconsole, detail::default_set_console_dest,
×
1024
                detail::default_define_formatters);
×
1025
            detail::init_debuglog_console_log(
×
1026
                lvl, HPX_MOVE(logdest), HPX_MOVE(logformat));
×
1027
            break;
×
1028

1029
        case logging_destination::agas:
1030
            detail::init_agas_log(lvl, logdest, logformat,
×
1031
                detail::default_isconsole, detail::default_set_console_dest,
×
1032
                detail::default_define_formatters);
×
1033
            detail::init_agas_console_log(
×
1034
                lvl, HPX_MOVE(logdest), HPX_MOVE(logformat));
×
1035
            break;
×
1036

1037
        case logging_destination::parcel:
1038
            detail::init_parcel_log(lvl, logdest, logformat,
×
1039
                detail::default_isconsole, detail::default_set_console_dest,
×
1040
                detail::default_define_formatters);
×
1041
            detail::init_parcel_console_log(
×
1042
                lvl, HPX_MOVE(logdest), HPX_MOVE(logformat));
×
1043
            break;
×
1044

1045
        case logging_destination::app:
1046
            detail::init_app_log(lvl, logdest, logformat,
×
1047
                detail::default_isconsole, detail::default_set_console_dest,
×
1048
                detail::default_define_formatters);
×
1049
            detail::init_app_console_log(
×
1050
                lvl, HPX_MOVE(logdest), HPX_MOVE(logformat));
×
1051
            break;
×
1052

1053
        case logging_destination::debuglog:
1054
            detail::init_debuglog_log(lvl, logdest, logformat,
×
1055
                detail::default_isconsole, detail::default_set_console_dest,
×
1056
                detail::default_define_formatters);
×
1057
            detail::init_debuglog_console_log(
×
1058
                lvl, HPX_MOVE(logdest), HPX_MOVE(logformat));
×
1059
            break;
×
1060
        }
1061
    }
×
1062
}}    // namespace hpx::util
1063

1064
#else
1065

1066
#include <hpx/init_runtime_local/detail/init_logging.hpp>
1067
#include <hpx/modules/logging.hpp>
1068
#include <hpx/util/get_entry_as.hpp>
1069

1070
#include <iostream>
1071
#include <string>
1072

1073
namespace hpx { namespace util {
1074

1075
    //////////////////////////////////////////////////////////////////////////
1076
    void enable_logging(
1077
        logging_destination, std::string const&, std::string, std::string)
1078
    {
1079
    }
1080

1081
    void disable_logging(logging_destination) {}
1082

1083
    //////////////////////////////////////////////////////////////////////////
1084
    namespace detail {
1085

1086
        void warn_if_logging_requested(runtime_configuration& ini)
1087
        {
1088
            using util::get_entry_as;
1089

1090
            // warn if logging is requested
1091
            if (get_entry_as<int>(ini, "hpx.logging.level", -1) > 0 ||
1092
                get_entry_as<int>(ini, "hpx.logging.timing.level", -1) > 0 ||
1093
                get_entry_as<int>(ini, "hpx.logging.agas.level", -1) > 0 ||
1094
                get_entry_as<int>(ini, "hpx.logging.debuglog.level", -1) > 0 ||
1095
                get_entry_as<int>(ini, "hpx.logging.application.level", -1) > 0)
1096
            {
1097
                std::cerr
1098
                    << "hpx::init_logging: warning: logging is requested even "
1099
                       "while it was disabled at compile time. If you "
1100
                       "need logging to be functional, please reconfigure and "
1101
                       "rebuild HPX with HPX_WITH_LOGGING set to ON."
1102
                    << std::endl;
1103
            }
1104
        }
1105
    }    // namespace detail
1106
}}       // namespace hpx::util
1107

1108
#endif    // HPX_HAVE_LOGGING
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc