79a7fd474a94bad0df6a5fef570944ee0b1d5eb2
[platform/core/security/security-manager.git] / src / dpl / log / src / dlog_log_provider.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file        dlog_log_provider.cpp
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the implementation file of DLOG log provider
21  */
22 #include <stddef.h>
23 #include <dpl/log/dlog_log_provider.h>
24 #include <cstring>
25 #include <sstream>
26 #include <dlog.h>
27
28 #define UNUSED __attribute__((unused))
29
30 namespace SecurityManager {
31 namespace Log {
32 std::string DLOGLogProvider::FormatMessage(const char *message,
33                                            const char *filename,
34                                            int line,
35                                            const char *function)
36 {
37     std::ostringstream val;
38
39     val << std::string("[") <<
40     LocateSourceFileName(filename) << std::string(":") << line <<
41     std::string("] ") << function << std::string("(): ") << message;
42
43     return val.str();
44 }
45
46 DLOGLogProvider::DLOGLogProvider()
47 {}
48
49 DLOGLogProvider::~DLOGLogProvider()
50 {}
51
52 void DLOGLogProvider::SetTag(const char *tag)
53 {
54     size_t size = strlen(tag)+1;
55     char *buff = new (std::nothrow) char[size];
56     if (buff)
57         memcpy(buff, tag, size);
58     m_tag.reset(buff);
59 }
60
61 void DLOGLogProvider::Debug(const char *message,
62                             const char *filename,
63                             int line,
64                             const char *function)
65 {
66     SLOG(LOG_DEBUG, m_tag.get(), "%s",
67         FormatMessage(message, filename, line, function).c_str());
68 }
69
70 void DLOGLogProvider::Info(const char *message,
71                            const char *filename,
72                            int line,
73                            const char *function)
74 {
75     SLOG(LOG_INFO, m_tag.get(), "%s",
76         FormatMessage(message, filename, line, function).c_str());
77 }
78
79 void DLOGLogProvider::Warning(const char *message,
80                               const char *filename,
81                               int line,
82                               const char *function)
83 {
84     SLOG(LOG_WARN, m_tag.get(), "%s",
85         FormatMessage(message, filename, line, function).c_str());
86 }
87
88 void DLOGLogProvider::Error(const char *message,
89                             const char *filename,
90                             int line,
91                             const char *function)
92 {
93     SLOG(LOG_ERROR, m_tag.get(), "%s",
94         FormatMessage(message, filename, line, function).c_str());
95 }
96
97 void DLOGLogProvider::Pedantic(const char *message,
98                                const char *filename,
99                                int line,
100                                const char *function)
101 {
102     SLOG(LOG_DEBUG, "SecurityManager", "%s", FormatMessage(message,
103                                               filename,
104                                               line,
105                                               function).c_str());
106 }
107
108 } // nemespace Log
109 } // namespace SecurityManager