forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.hpp
50 lines (40 loc) · 1.16 KB
/
log.hpp
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
/**
* @file
*
* @brief Log data using Elektra’s logging facility
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#ifndef ELEKTRA_PLUGIN_YAMLCPP_LOG_HPP
#define ELEKTRA_PLUGIN_YAMLCPP_LOG_HPP
#include <kdb.hpp>
#include <kdblogger.h>
#ifdef HAVE_LOGGER
namespace
{
/**
* @brief This function uses Elektra’s logging facility to print the contents of a key set.
*
* @param keys This parameter stores the key set this function prints.
*/
void logKeySet (kdb::KeySet const & keys)
{
for (auto key : keys)
{
std::string metadata;
ckdb::KeySet * metaKeys = ckdb::keyMeta (key.getKey ());
for (elektraCursor it = 0; it < ckdb::ksGetSize (metaKeys); ++it)
{
const kdb::Key curMeta (ckdb::ksAtCursor (metaKeys, it));
metadata += ", “" + curMeta.getName () + "”: “" + curMeta.getString () + "”";
}
ELEKTRA_LOG_DEBUG ("\t“%s”: “%s”%s", key.getName ().c_str (),
key.getBinarySize () == 0 ? "NULL" :
key.isBinary () ? "binary value!" :
key.getString ().c_str (),
metadata.c_str ());
}
}
} // end namespace
#endif // HAVE_LOGGER
#endif // ELEKTRA_PLUGIN_YAMLCPP_LOG_HPP