Source code formating unification
[framework/web/wrt-commons.git] / modules / 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 namespace DPL {
29 namespace Log {
30 std::string DLOGLogProvider::FormatMessage(const char *message,
31                                            const char *filename,
32                                            int line,
33                                            const char *function)
34 {
35     std::ostringstream val;
36
37     val << std::string("[") <<
38     LocateSourceFileName(filename) << std::string(":") << line <<
39     std::string("] ") << function << std::string("(): ") << message;
40
41     return val.str();
42 }
43
44 DLOGLogProvider::DLOGLogProvider()
45 {}
46
47 DLOGLogProvider::~DLOGLogProvider()
48 {}
49
50 void DLOGLogProvider::SetTag(const char *tag)
51 {
52     m_tag.Reset(strdup(tag));
53 }
54
55 void DLOGLogProvider::Debug(const char *message,
56                             const char *filename,
57                             int line,
58                             const char *function)
59 {
60     LOG(LOG_DEBUG, m_tag.Get(), "%s",
61         FormatMessage(message, filename, line, function).c_str());
62 }
63
64 void DLOGLogProvider::Info(const char *message,
65                            const char *filename,
66                            int line,
67                            const char *function)
68 {
69     LOG(LOG_INFO, m_tag.Get(), "%s",
70         FormatMessage(message, filename, line, function).c_str());
71 }
72
73 void DLOGLogProvider::Warning(const char *message,
74                               const char *filename,
75                               int line,
76                               const char *function)
77 {
78     LOG(LOG_WARN, m_tag.Get(), "%s",
79         FormatMessage(message, filename, line, function).c_str());
80 }
81
82 void DLOGLogProvider::Error(const char *message,
83                             const char *filename,
84                             int line,
85                             const char *function)
86 {
87     LOG(LOG_ERROR, m_tag.Get(), "%s",
88         FormatMessage(message, filename, line, function).c_str());
89 }
90
91 void DLOGLogProvider::Pedantic(const char *message,
92                                const char *filename,
93                                int line,
94                                const char *function)
95 {
96     LOG(LOG_DEBUG, "DPL", "%s", FormatMessage(message,
97                                               filename,
98                                               line,
99                                               function).c_str());
100 }
101 }
102 } // namespace DPL