summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/OSLogLoggerI.cpp
blob: a5c3432790adfa7d3fce7ede971d03f6e9c72be3 (plain)
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
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

#ifdef ICE_SWIFT

#include <Ice/OSLogLoggerI.h>
#include <os/log.h>

using namespace std;
using namespace Ice;

Ice::OSLogLoggerI::OSLogLoggerI(const std::string& prefix) : _prefix(prefix)
{
    const string subsystem = prefix.empty() ? "com.zeroc.ice" : "com.zeroc.ice." + prefix;
    _log.reset(os_log_create(subsystem.c_str(), ""));
}

void
Ice::OSLogLoggerI::print(const std::string& message)
{
    os_log_with_type(_log.get(), OS_LOG_TYPE_DEFAULT, "%{public}s.", message.c_str());
}

void
Ice::OSLogLoggerI::trace(const std::string& category, const std::string& message)
{
    const string subsystem = _prefix.empty() ? "com.zeroc.ice" : "com.zeroc.ice." + _prefix;
    IceInternal::UniqueRef<os_log_t> log(os_log_create(subsystem.c_str(), category.c_str()));
    os_log_with_type(log.get(), OS_LOG_TYPE_INFO, "%{public}s.", message.c_str());
}

void
Ice::OSLogLoggerI::warning(const std::string& message)
{
    os_log_with_type(_log.get(), OS_LOG_TYPE_ERROR, "%{public}s.", message.c_str());
}

void
Ice::OSLogLoggerI::error(const std::string& message)
{
    os_log_with_type(_log.get(), OS_LOG_TYPE_FAULT, "%{public}s.", message.c_str());
}

std::string
Ice::OSLogLoggerI::getPrefix()
{
    return _prefix;
}

LoggerPtr
Ice::OSLogLoggerI::cloneWithPrefix(const std::string& prefix)
{
    return ICE_MAKE_SHARED(OSLogLoggerI, prefix);
}

#endif