Skip to content

Commit

Permalink
Merge 487a7b0 into b6f1a9a
Browse files Browse the repository at this point in the history
  • Loading branch information
msimberg authored Mar 28, 2023
2 parents b6f1a9a + 487a7b0 commit 98cfe91
Show file tree
Hide file tree
Showing 4 changed files with 508 additions and 524 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,79 @@
#pragma once

#include <pika/config.hpp>
#include <pika/logging/format/named_write.hpp>
#include <pika/logging/level.hpp>
#include <pika/logging/manipulator.hpp>
#include <pika/logging/message.hpp>
#include <pika/modules/logging.hpp>
#include <pika/runtime_configuration/runtime_configuration.hpp>

#include <string>

#if defined(PIKA_HAVE_LOGGING)
///////////////////////////////////////////////////////////////////////////////
namespace pika::util {
namespace pika::detail {

/// \cond NOINTERNAL

///////////////////////////////////////////////////////////////////////////
// custom log destination: send generated strings to console
struct PIKA_EXPORT console_local : logging::destination::manipulator
struct PIKA_EXPORT console_local : pika::util::logging::destination::manipulator
{
console_local(logging::level level, logging_destination dest)
console_local(pika::util::logging::level level, pika::logging_destination dest)
: level_(level)
, dest_(dest)
{
}

void operator()(logging::message const& msg) override;
void operator()(pika::util::logging::message const& msg) override;

friend bool operator==(console_local const& lhs, console_local const& rhs)
{
return lhs.dest_ == rhs.dest_;
}

logging::level level_;
logging_destination dest_;
pika::util::logging::level level_;
pika::logging_destination dest_;
};

///////////////////////////////////////////////////////////////////////////
namespace detail {

struct log_settings
{
std::string level_;
std::string dest_;
std::string format_;
};
struct log_settings
{
std::string level_;
std::string dest_;
std::string format_;
};

PIKA_EXPORT void define_common_formatters(logging::writer::named_write& writer);
PIKA_EXPORT void define_common_formatters(pika::util::logging::writer::named_write& writer);

PIKA_EXPORT void define_formatters_local(logging::writer::named_write& writer);
PIKA_EXPORT void define_formatters_local(pika::util::logging::writer::named_write& writer);

PIKA_EXPORT log_settings get_log_settings(util::section const&, char const*);
PIKA_EXPORT log_settings get_log_settings(util::section const&, char const*);

PIKA_EXPORT void init_logging(runtime_configuration& ini, bool isconsole,
void (*set_console_dest)(
logging::writer::named_write&, char const*, logging::level, logging_destination),
void (*define_formatters)(logging::writer::named_write&));
PIKA_EXPORT void init_logging(pika::util::runtime_configuration& ini, bool isconsole,
void (*set_console_dest)(pika::util::logging::writer::named_write&, char const*,
pika::util::logging::level, pika::logging_destination),
void (*define_formatters)(pika::util::logging::writer::named_write&));

PIKA_EXPORT void init_logging_local(runtime_configuration&);
} // namespace detail
PIKA_EXPORT void init_logging_local(pika::util::runtime_configuration&);

/// \endcond

//////////////////////////////////////////////////////////////////////////
/// Enable logging for given destination
PIKA_EXPORT void enable_logging(logging_destination dest, std::string const& lvl = "5",
PIKA_EXPORT void enable_logging(pika::logging_destination dest, std::string const& lvl = "5",
std::string logdest = "", std::string logformat = "");

/// Disable all logging for the given destination
PIKA_EXPORT void disable_logging(logging_destination dest);
} // namespace pika::util
PIKA_EXPORT void disable_logging(pika::logging_destination dest);
} // namespace pika::detail

#else // PIKA_HAVE_LOGGING

namespace pika { namespace util {
namespace detail {

PIKA_EXPORT void warn_if_logging_requested(runtime_configuration&);
}
namespace pika::detail {
PIKA_EXPORT void warn_if_logging_requested(pika::util::runtime_configuration&);

//////////////////////////////////////////////////////////////////////////
PIKA_EXPORT void enable_logging(logging_destination dest, std::string const& lvl = "5",
PIKA_EXPORT void enable_logging(pika::logging_destination dest, std::string const& lvl = "5",
std::string logdest = "", std::string logformat = "");

PIKA_EXPORT void disable_logging(logging_destination dest);
}} // namespace pika::util
PIKA_EXPORT void disable_logging(pika::logging_destination dest);
} // namespace pika::detail

#endif // PIKA_HAVE_LOGGING
76 changes: 16 additions & 60 deletions libs/pika/init_runtime/include/pika/init_runtime/init_runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ namespace pika {
namespace detail {
PIKA_EXPORT int init_helper(
pika::program_options::variables_map&, util::detail::function<int(int, char**)> const&);
}

namespace detail {
struct dump_config
{
dump_config(pika::runtime const& rt)
Expand Down Expand Up @@ -127,64 +125,22 @@ namespace pika {
}
} // namespace detail

inline int init(std::function<int(pika::program_options::variables_map&)> f, int argc,
const char* const* argv, init_params const& params = init_params())
{
return detail::init_start_impl(PIKA_MOVE(f), argc, argv, params, true);
}

inline int init(std::function<int(int, char**)> f, int argc, const char* const* argv,
init_params const& params = init_params())
{
util::detail::function<int(pika::program_options::variables_map&)> main_f =
pika::util::detail::bind_back(pika::detail::init_helper, f);
return detail::init_start_impl(PIKA_MOVE(main_f), argc, argv, params, true);
}

inline int init(std::function<int()> f, int argc, const char* const* argv,
init_params const& params = init_params())
{
util::detail::function<int(pika::program_options::variables_map&)> main_f =
pika::util::detail::bind(f);
return detail::init_start_impl(PIKA_MOVE(main_f), argc, argv, params, true);
}

inline int init(std::nullptr_t, int argc, const char* const* argv,
init_params const& params = init_params())
{
util::detail::function<int(pika::program_options::variables_map&)> main_f;
return detail::init_start_impl(PIKA_MOVE(main_f), argc, argv, params, true);
}

inline bool start(std::function<int(pika::program_options::variables_map&)> f, int argc,
const char* const* argv, init_params const& params = init_params())
{
return 0 == detail::init_start_impl(PIKA_MOVE(f), argc, argv, params, false);
}

inline bool start(std::function<int(int, char**)> f, int argc, const char* const* argv,
init_params const& params = init_params())
{
util::detail::function<int(pika::program_options::variables_map&)> main_f =
pika::util::detail::bind_back(pika::detail::init_helper, f);
return 0 == detail::init_start_impl(PIKA_MOVE(main_f), argc, argv, params, false);
}

inline bool start(std::function<int()> f, int argc, const char* const* argv,
init_params const& params = init_params())
{
util::detail::function<int(pika::program_options::variables_map&)> main_f =
pika::util::detail::bind(f);
return 0 == detail::init_start_impl(PIKA_MOVE(main_f), argc, argv, params, false);
}

inline bool start(std::nullptr_t, int argc, const char* const* argv,
init_params const& params = init_params())
{
util::detail::function<int(pika::program_options::variables_map&)> main_f;
return 0 == detail::init_start_impl(PIKA_MOVE(main_f), argc, argv, params, false);
}

PIKA_EXPORT int init(std::function<int(pika::program_options::variables_map&)> f, int argc,
const char* const* argv, init_params const& params = init_params());
PIKA_EXPORT int init(std::function<int(int, char**)> f, int argc, const char* const* argv,
init_params const& params = init_params());
PIKA_EXPORT int init(std::function<int()> f, int argc, const char* const* argv,
init_params const& params = init_params());
PIKA_EXPORT int init(std::nullptr_t, int argc, const char* const* argv,
init_params const& params = init_params());
PIKA_EXPORT bool start(std::function<int(pika::program_options::variables_map&)> f, int argc,
const char* const* argv, init_params const& params = init_params());
PIKA_EXPORT bool start(std::function<int(int, char**)> f, int argc, const char* const* argv,
init_params const& params = init_params());
PIKA_EXPORT bool start(std::function<int()> f, int argc, const char* const* argv,
init_params const& params = init_params());
PIKA_EXPORT bool start(std::nullptr_t, int argc, const char* const* argv,
init_params const& params = init_params());
PIKA_EXPORT int finalize(error_code& ec = throws);
PIKA_EXPORT int stop(error_code& ec = throws);
PIKA_EXPORT int suspend(error_code& ec = throws);
Expand Down
Loading

0 comments on commit 98cfe91

Please sign in to comment.