1 /*
2  * Log.hpp
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 
16 #ifndef CORE_LOG_HPP
17 #define CORE_LOG_HPP
18 
19 #include <shared_core/Logger.hpp>
20 
21 #include <string>
22 
23 #include <shared_core/Error.hpp>
24 #include <boost/function.hpp>
25 
26 namespace rstudio {
27 namespace core {
28 namespace log {
29 
30 enum class LoggerType
31 {
32    kStdErr = 0,
33    kSysLog = 1,
34    kFile = 2
35 };
36 
37 void logDebugAction(const boost::function<std::string()>& action,
38                     const ErrorLocation& loggedFromLocation = ErrorLocation());
39 
40 void logDebugAction(const std::string& logSection,
41                     const boost::function<std::string()>& action,
42                     const ErrorLocation& loggedFromLocation = ErrorLocation());
43 
44 std::string errorAsLogEntry(const Error& error);
45 
46 // Macros for automatic inclusion of ERROR_LOCATION and easy ability to
47 // compile out logging calls
48 
49 #define LOG_ERROR(error) rstudio::core::log::logError(error, \
50                                                       ERROR_LOCATION)
51 
52 #define LOG_ERROR_NAMED(logSection, error) rstudio::core::log::logError(logSection, \
53                                                                         error, \
54                                                                         ERROR_LOCATION)
55 
56 #define LOG_ERROR_MESSAGE(message) rstudio::core::log::logErrorMessage(message, \
57                                                                        ERROR_LOCATION)
58 
59 #define LOG_ERROR_MESSAGE_NAMED(logSection, message) rstudio::core::log::logErrorMessage(message, \
60                                                                                          logSection, \
61                                                                                          ERROR_LOCATION)
62 
63 #define LOG_WARNING_MESSAGE(message) rstudio::core::log::logWarningMessage(message, \
64                                                                            ERROR_LOCATION)
65 
66 #define LOG_WARNING_MESSAGE_NAMED(logSection, message) rstudio::core::log::logWarningMessage(message, \
67                                                                                              logSection, \
68                                                                                              ERROR_LOCATION)
69 
70 #define LOG_INFO_MESSAGE(message) rstudio::core::log::logInfoMessage(message)
71 
72 #define LOG_INFO_MESSAGE_NAMED(logSection, message) rstudio::core::log::logInfoMessage(message, \
73                                                                                        logSection)
74 
75 #define LOG_DEBUG_MESSAGE(message) rstudio::core::log::logDebugMessage(message)
76 
77 #define LOG_DEBUG_ACTION(action) rstudio::core::log::logDebugAction(action)
78 
79 #define LOG_DEBUG_MESSAGE_NAMED(logSection, message) rstudio::core::log::logDebugMessage(message, \
80                                                                                          logSection)
81 
82 #define LOG_DEBUG_ACTION_NAMED(logSection, action) rstudio::core::log::logDebugAction(logSection, \
83                                                                                       action)
84 
85 // define named logging sections
86 #define kFileLockingLogSection "file-locking"
87 
88 } // namespace log
89 } // namespace core
90 } // namespace rstudio
91 
92 #endif // CORE_LOG_HPP
93