2 * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * \ingroup Implementation
24 #define LOG_TAG "LIBDBUSPOLICY"
34 enum class ldp_log_level {
42 /** Checks value of environmental variable with given name */
43 bool get_log_env(char const *name);
45 /** Checks environmental variables and sets global variable defining if logs are enabled */
46 void init(ldp_log_level level = ldp_log_level::SILENT);
48 /** Checks if logs are enabled */
49 bool enabled(ldp_log_level level = ldp_log_level::DEBUG);
51 void flush(ldp_log_level level = ldp_log_level::ERROR);
53 void logError(const std::string &error);
54 void logWarning(const std::string &warning);
55 void logDebug(const std::string &debug);
56 void logVerbose(const std::string &verbose);
58 template <typename ...Args>
59 void log_to_stream(std::ostream &stream, const Args &...args) {
60 std::initializer_list<int>{((void)(stream << args), 0)...};
63 template <typename ...Args>
64 void log_debug(const Args &...args) { if (enabled(ldp_log_level::DEBUG)) log_to_stream(std::cout, args...); }
66 template <typename ...Args>
67 void log_error(const Args &...args) { if (enabled(ldp_log_level::ERROR)) log_to_stream(std::cout, args...); }
69 template <typename ...Args>
70 void log_warning(const Args &...args) { if (enabled(ldp_log_level::WARNING)) log_to_stream(std::cout, args...); }
72 template <typename ...Args>
73 void log_verbose(const Args &...args) { if (enabled(ldp_log_level::VERBOSE)) log_to_stream(std::cout, args...); }
77 explicit print_errno(int e) : err(e) {}
80 std::ostream &operator<<(std::ostream &stream, const print_errno &p);
82 /* Use this class to ensure that logs from a given function are not interlaced
83 * with logs from another function
88 explicit LogLock(ldp_log_level level = ldp_log_level::ERROR);