2 * Copyright (c) 2011 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.
17 * @file old_style_log_provider.cpp
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of old style log provider
23 #include <dpl/log/old_style_log_provider.h>
24 #include <dpl/colors.h>
33 namespace // anonymous
35 using namespace DPL::Colors::Text;
36 const char *DEBUG_BEGIN = GREEN_BEGIN;
37 const char *DEBUG_END = GREEN_END;
38 const char *INFO_BEGIN = CYAN_BEGIN;
39 const char *INFO_END = CYAN_END;
40 const char *ERROR_BEGIN = RED_BEGIN;
41 const char *ERROR_END = RED_END;
42 const char *WARNING_BEGIN = BOLD_GOLD_BEGIN;
43 const char *WARNING_END = BOLD_GOLD_END;
44 const char *PEDANTIC_BEGIN = PURPLE_BEGIN;
45 const char *PEDANTIC_END = PURPLE_END;
47 std::string GetFormattedTime()
52 gettimeofday(&tv, NULL);
53 localtime_r(&tv.tv_sec, &localNowTime);
58 "%02i:%02i:%02i.%03i",
62 static_cast<int>(tv.tv_usec / 1000));
65 } // namespace anonymous
67 std::string OldStyleLogProvider::FormatMessage(const char *message,
72 std::ostringstream val;
74 val << std::string("[") << GetFormattedTime() << std::string("] [") <<
75 static_cast<unsigned long>(pthread_self()) << "/" <<
76 static_cast<int>(getpid()) << std::string("] [") <<
77 LocateSourceFileName(filename) << std::string(":") << line <<
78 std::string("] ") << function << std::string("(): ") << message;
83 OldStyleLogProvider::OldStyleLogProvider(bool showDebug,
88 m_showDebug(showDebug),
90 m_showWarning(showWarning),
91 m_showError(showError),
92 m_showPedantic(showPedantic)
95 void OldStyleLogProvider::Debug(const char *message,
101 fprintf(stdout, "%s%s%s\n", DEBUG_BEGIN,
102 FormatMessage(message, filename, line,
103 function).c_str(), DEBUG_END);
107 void OldStyleLogProvider::Info(const char *message,
108 const char *filename,
110 const char *function)
113 fprintf(stdout, "%s%s%s\n", INFO_BEGIN,
114 FormatMessage(message, filename, line,
115 function).c_str(), INFO_END);
119 void OldStyleLogProvider::Warning(const char *message,
120 const char *filename,
122 const char *function)
125 fprintf(stdout, "%s%s%s\n", WARNING_BEGIN,
126 FormatMessage(message, filename, line,
127 function).c_str(), WARNING_END);
131 void OldStyleLogProvider::Error(const char *message,
132 const char *filename,
134 const char *function)
137 fprintf(stdout, "%s%s%s\n", ERROR_BEGIN,
138 FormatMessage(message, filename, line,
139 function).c_str(), ERROR_END);
143 void OldStyleLogProvider::Pedantic(const char *message,
144 const char *filename,
146 const char *function)
148 if (m_showPedantic) {
149 fprintf(stdout, "%s%s%s\n", PEDANTIC_BEGIN,
150 FormatMessage(message, filename, line,
151 function).c_str(), PEDANTIC_END);