Fix invalid licenses
[platform/framework/web/crosswalk-tizen.git] / src / common / logger.h
1 /*
2  * Copyright (c) 2015 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 #ifndef WRT_COMMON_LOGGER_H_
18 #define WRT_COMMON_LOGGER_H_
19
20 #include <dlog.h>
21 #include <sstream>
22
23 #undef LOGGER_TAG
24 #define LOGGER_TAG "WRT"
25
26 #define _LOGGER_LOG(prio, fmt, args...) \
27   LOG_(LOG_ID_MAIN, prio, LOGGER_TAG, fmt, ##args)
28
29 #define _LOGGER_SLOG(prio, fmt, args...) \
30   SECURE_LOG_(LOG_ID_MAIN, prio, LOGGER_TAG, fmt, ##args)
31
32 #define LoggerD(fmt, args...) _LOGGER_LOG(DLOG_DEBUG, fmt, ##args)
33 #define LoggerI(fmt, args...) _LOGGER_LOG(DLOG_INFO, fmt, ##args)
34 #define LoggerW(fmt, args...) _LOGGER_LOG(DLOG_WARN, fmt, ##args)
35 #define LoggerE(fmt, args...) _LOGGER_LOG(DLOG_ERROR, fmt, ##args)
36
37 #define SLoggerD(fmt, args...) _LOGGER_SLOG(DLOG_DEBUG, fmt, ##args)
38 #define SLoggerI(fmt, args...) _LOGGER_SLOG(DLOG_INFO, fmt, ##args)
39 #define SLoggerW(fmt, args...) _LOGGER_SLOG(DLOG_WARN, fmt, ##args)
40 #define SLoggerE(fmt, args...) _LOGGER_SLOG(DLOG_ERROR, fmt, ##args)
41
42 namespace wrt {
43 namespace utils {
44
45 class LogMessageVodify {
46  public:
47   LogMessageVodify() {}
48   void operator&(const std::ostream&) const {}
49 };
50
51 class LogMessage {
52  public:
53   LogMessage(int severity, const char* file, const char* func, const int line)
54       : severity_(severity), file_(file), func_(func), line_(line) {}
55   ~LogMessage() {
56     __dlog_print(LOG_ID_MAIN, severity_, LOGGER_TAG,
57                  "%s: %s(%d) > %s", file_, func_, line_, stream_.str().c_str());
58   }
59   std::ostream& stream() { return stream_; }
60  private:
61   const int severity_;
62   const char* file_;
63   const char* func_;
64   const int line_;
65   std::ostringstream stream_;
66 };
67
68 }  // namespace utils
69 }  // namespace wrt
70
71 #ifndef __MODULE__
72 #define __MODULE__                                                            \
73     (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
74 #endif
75
76 #define LOGGER(severity)                                                      \
77   wrt::utils::LogMessageVodify() &                                            \
78     wrt::utils::LogMessage(DLOG_ ## severity,                                 \
79                            __MODULE__, __FUNCTION__, __LINE__).stream()
80
81
82 #endif  // WRT_COMMON_LOGGER_H_