Added libLogger's documentation
[platform/core/security/vasum.git] / libs / logger / logger-scope.hpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Lukasz Kostyra <l.kostyra@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18
19 /**
20  * @file
21  * @author  Lukasz Kostyra (l.kostyra@samsung.com)
22  * @brief   Scope logger class declaration
23  */
24
25 #ifndef COMMON_LOGGER_LOGGER_SCOPE_HPP
26 #define COMMON_LOGGER_LOGGER_SCOPE_HPP
27
28 #include <string>
29 #include <sstream>
30
31 namespace logger {
32
33 class SStreamWrapper
34 {
35 public:
36     operator std::string() const;
37
38     template <typename T>
39     SStreamWrapper& operator<<(const T& b)
40     {
41         this->mSStream << b;
42         return *this;
43     }
44
45 private:
46     std::ostringstream mSStream;
47 };
48
49 /**
50  * Class specifically for scope debug logging. Should be used at the beggining of a scope.
51  * Constructor marks scope enterance, destructor marks scope leave.
52  */
53 class LoggerScope
54 {
55 public:
56     LoggerScope(const std::string& file,
57                 const unsigned int line,
58                 const std::string& func,
59                 const std::string& message,
60                 const std::string& rootDir);
61     ~LoggerScope();
62
63 private:
64     const std::string mFile;
65     const unsigned int mLine;
66     const std::string mFunc;
67     const std::string mMessage;
68     const std::string mRootDir;
69 };
70
71 } // namespace logger
72
73 /**
74  * @brief Automatically create LoggerScope object which logs at the construction and destruction
75  * @ingroup libLogger
76  */
77 #define LOGS(MSG)   logger::LoggerScope logScopeObj(__FILE__, __LINE__, __func__,    \
78                                                     logger::SStreamWrapper() << MSG, \
79                                                     PROJECT_SOURCE_DIR)
80
81 #endif // COMMON_LOGGER_LOGGER_SCOPE_HPP