-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created class LoggerGlog which is an implementation of ILogger. #137
- Loading branch information
1 parent
afa8af9
commit 2d2b43f
Showing
7 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
add_library(sa.logger.glog SHARED | ||
LoggerGlog.cpp | ||
LoggerGlog.h | ||
) | ||
|
||
# Force CMAKE_DEBUG_POSTFIX for executables | ||
set_target_properties(sa.logger.glog PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) | ||
|
||
set(SA_GLOG_EXPORT_HEADER_FILENAME "sa_glog_export.h") | ||
set(SA_GLOG_EXPORT_HEADER ${CMAKE_BINARY_DIR}/src/logger/glog/${SA_GLOG_EXPORT_HEADER_FILENAME}) | ||
message("Generating ${SA_GLOG_EXPORT_HEADER_FILENAME} for shared library...") | ||
include (GenerateExportHeader) | ||
GENERATE_EXPORT_HEADER( sa.logger.glog | ||
BASE_NAME sa_glog | ||
EXPORT_MACRO_NAME SA_GLOG_EXPORT | ||
EXPORT_FILE_NAME ${SA_GLOG_EXPORT_HEADER} | ||
) | ||
|
||
# Define include directories for the library. | ||
target_include_directories(sa.logger.glog | ||
PUBLIC | ||
$<INSTALL_INTERFACE:${SHELLANYTHING_INSTALL_INCLUDE_DIR}> # for clients using the installed library. | ||
PRIVATE | ||
rapidassist | ||
glog::glog | ||
${CMAKE_SOURCE_DIR}/src/core | ||
${CMAKE_BINARY_DIR}/src/logger/glog | ||
) | ||
|
||
# Define linking dependencies. | ||
add_dependencies(sa.logger.glog sa.core) | ||
target_link_libraries(sa.logger.glog | ||
PRIVATE | ||
rapidassist | ||
glog::glog | ||
sa.core | ||
) | ||
|
||
# Define files that will be part of the installation package. | ||
install(TARGETS sa.logger.glog | ||
EXPORT sa-glog-targets | ||
ARCHIVE DESTINATION ${SHELLANYTHING_INSTALL_LIB_DIR} | ||
LIBRARY DESTINATION ${SHELLANYTHING_INSTALL_LIB_DIR} | ||
RUNTIME DESTINATION ${SHELLANYTHING_INSTALL_BIN_DIR} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/********************************************************************************** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Antoine Beauchamp | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*********************************************************************************/ | ||
|
||
#include "LoggerGlog.h" | ||
|
||
#pragma warning( push ) | ||
#pragma warning( disable: 4355 ) // glog\install_dir\include\glog/logging.h(1167): warning C4355: 'this' : used in base member initializer list | ||
#include <glog/logging.h> | ||
#pragma warning( pop ) | ||
|
||
namespace shellanything | ||
{ | ||
|
||
inline ::google::LogSeverity to_severity(const ILogger::LOG_LEVEL& level) | ||
{ | ||
switch (level) | ||
{ | ||
default: | ||
case ILogger::LOG_LEVEL_DEBUG: | ||
case ILogger::LOG_LEVEL_INFO: | ||
return ::google::GLOG_INFO; | ||
break; | ||
case ILogger::LOG_LEVEL_WARNING: | ||
return ::google::GLOG_WARNING; | ||
break; | ||
case ILogger::LOG_LEVEL_ERROR: | ||
return ::google::GLOG_ERROR; | ||
break; | ||
case ILogger::LOG_LEVEL_FATAL: | ||
return ::google::GLOG_FATAL; | ||
break; | ||
}; | ||
} | ||
|
||
LoggerGlog::LoggerGlog() | ||
{ | ||
} | ||
|
||
LoggerGlog::~LoggerGlog() | ||
{ | ||
} | ||
|
||
void LoggerGlog::LogMessage(const char* filename, int line, const ILogger::LOG_LEVEL& level, const char* message) | ||
{ | ||
::google::LogMessage(filename, line, to_severity(level)).stream() << message; | ||
} | ||
|
||
void LoggerGlog::LogMessage(const ILogger::LOG_LEVEL& level, const char* message) | ||
{ | ||
::google::LogMessage(__FILE__, __LINE__, to_severity(level)).stream() << message; | ||
} | ||
|
||
} //namespace shellanything |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/********************************************************************************** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Antoine Beauchamp | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*********************************************************************************/ | ||
|
||
#ifndef SA_LOGGER_GLOG_H | ||
#define SA_LOGGER_GLOG_H | ||
|
||
#include "sa_glog_export.h" | ||
#include "ILogger.h" | ||
|
||
namespace shellanything | ||
{ | ||
/// <summary> | ||
/// Abstract logger class. | ||
/// </summary> | ||
class SA_GLOG_EXPORT LoggerGlog : public virtual ILogger | ||
{ | ||
public: | ||
LoggerGlog(); | ||
virtual ~LoggerGlog(); | ||
|
||
private: | ||
// Disable and copy constructor, dtor and copy operator | ||
LoggerGlog(const LoggerGlog&); | ||
LoggerGlog& operator=(const LoggerGlog&); | ||
public: | ||
|
||
/// <summary> | ||
/// Send a message to this logger. | ||
/// </summary> | ||
/// <param name="filename">The originating source code file name.</param> | ||
/// <param name="line">The line number that producing this message.</param> | ||
/// <param name="level">The log level of the message.</param> | ||
/// <param name="message">The actual message.</param> | ||
virtual void LogMessage(const char* filename, int line, const ILogger::LOG_LEVEL & level, const char* message); | ||
|
||
/// <summary> | ||
/// Send a message to this logger. | ||
/// </summary> | ||
/// <param name="level">The log level of the message.</param> | ||
/// <param name="message">The actual message.</param> | ||
virtual void LogMessage(const ILogger::LOG_LEVEL & level, const char* message); | ||
|
||
}; | ||
|
||
} //namespace shellanything | ||
|
||
#endif //SA_LOGGER_GLOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters