Skip to content

Commit

Permalink
Merge branch 'feature-issue137' #137
Browse files Browse the repository at this point in the history
* feature-issue137:
  * Fixed issue #137: Library independent logging support.
  Fixed error in how to define the application's file name based on running from the shell extension's (i.e: through explorer.exe) or from unit tests executable.
  Fixed warning: 1>CUSTOMBUILD : CMake error : install(EXPORT "shellanything-targets" ...) includes target "sa.shellextension" which requires target "sa.logger.glog" that is not in any export set.
  Removed GLOG dependency from sa.api, sa.shellextension, sa.shared and sa.tests projects. #137
  Created function ShutdownGlog() in GlogUtil to prevent module having a dependency to google's glog/logging.h. Renamed function GlogUtils::InitLogger() to InitGlog(). #137
  Moved GlogUtils functions in shellanything::logging::glog namespace.
  Moved generic code from GlogUtils.cpp to ShellAnything's App class. #137 #111.
  Moved GlogUtils from /src/shared/ to /src/logger/glog/. #137
  Renamed LoggerManager class to App. #137 #111
  Moved glog include instruction from GlogUtils.h to GlogUtils.cpp.
  Removed usage of GLOG's `LOG` macro from files. #137
  Removed usage of GLOG's `LOG` macro from sa.shellextension project. #137
  Removed GLOG dependency from sa.core.dll. #137
  Added a temporary dllmain.cpp DLL un/initialization code for sa.logger.glog.dll. #137
  Created class LoggerGlog which is an implementation of ILogger. #137
  Created ILogger, LoggerManager and LoggerHelper classes. #137
  • Loading branch information
end2endzone committed Dec 6, 2023
2 parents d657874 + 730cad5 commit 4984c0d
Show file tree
Hide file tree
Showing 45 changed files with 1,117 additions and 470 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes for 0.9.0
* Fixed issue #127: Question Prompt action does not accept answers longer than the visual textbox.
* Fixed issue #132: Delete deprecated NSIS installer references.
* Fixed issue #133: Support for Github's Actions for the project.
* Fixed issue #137: Library independent logging support.


Changes for 0.8.0
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add_subdirectory(libexprtk)
add_subdirectory(core)
add_subdirectory(shellextension)
add_subdirectory(api)
add_subdirectory(logger/glog)

if(SHELLANYTHING_BUILD_PLUGINS)
add_subdirectory(plugins/sa_plugin_process)
Expand Down
2 changes: 0 additions & 2 deletions src/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ target_include_directories(sa.api
$<INSTALL_INTERFACE:${SHELLANYTHING_INSTALL_INCLUDE_DIR}> # for clients using the installed library.
PRIVATE
rapidassist
glog::glog
${CMAKE_SOURCE_DIR}/src/core
)

Expand All @@ -62,7 +61,6 @@ add_dependencies(sa.api sa.core)
target_link_libraries(sa.api
PRIVATE
rapidassist
glog::glog
sa.core
)

Expand Down
22 changes: 9 additions & 13 deletions src/api/sa_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,27 @@
*********************************************************************************/

#include "shellanything/sa_logging.h"
#include "LoggerHelper.h"
#include <stdarg.h> //for ...
#include <string>

#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 )

void sa_logging_print(sa_log_level_t level, const char* source_name, const char* message)
{
if (source_name)
{
switch (level)
{
case SA_LOG_LEVEL_INFO:
LOG(INFO) << "[ " << source_name << " ]: " << message;
SA_LOG(INFO) << "[ " << source_name << " ]: " << message;
break;
case SA_LOG_LEVEL_WARNING:
LOG(WARNING) << "[ " << source_name << " ]: " << message;
SA_LOG(WARNING) << "[ " << source_name << " ]: " << message;
break;
case SA_LOG_LEVEL_ERROR:
LOG(ERROR) << "[ " << source_name << " ]: " << message;
SA_LOG(ERROR) << "[ " << source_name << " ]: " << message;
break;
case SA_LOG_LEVEL_FATAL:
LOG(FATAL) << "[ " << source_name << " ]: " << message;
SA_LOG(FATAL) << "[ " << source_name << " ]: " << message;
break;
};
}
Expand All @@ -56,16 +52,16 @@ void sa_logging_print(sa_log_level_t level, const char* source_name, const char*
switch (level)
{
case SA_LOG_LEVEL_INFO:
LOG(INFO) << message;
SA_LOG(INFO) << message;
break;
case SA_LOG_LEVEL_WARNING:
LOG(WARNING) << message;
SA_LOG(WARNING) << message;
break;
case SA_LOG_LEVEL_ERROR:
LOG(ERROR) << message;
SA_LOG(ERROR) << message;
break;
case SA_LOG_LEVEL_FATAL:
LOG(FATAL) << message;
SA_LOG(FATAL) << message;
break;
};
}
Expand Down
8 changes: 2 additions & 6 deletions src/core/ActionClipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@
#include "PropertyManager.h"
#include "Win32Clipboard.h"
#include "ObjectFactory.h"
#include "LoggerHelper.h"

#include "rapidassist/unicode.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 )

#include "tinyxml2.h"
using namespace tinyxml2;

Expand Down Expand Up @@ -113,7 +109,7 @@ namespace shellanything
Win32Clipboard::Clipboard& clipboard = Win32Clipboard::Clipboard::GetInstance();

//debug
LOG(INFO) << "Setting clipboard to '" << value << "'.";
SA_LOG(INFO) << "Setting clipboard to '" << value << "'.";

//set clipboard value
bool result = clipboard.SetTextUtf8(value);
Expand Down
27 changes: 12 additions & 15 deletions src/core/ActionExecute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@
#include "rapidassist/filesystem_utf8.h"
#include "PropertyManager.h"
#include "ObjectFactory.h"
#include "LoggerHelper.h"

#include <windows.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 )

#include "tinyxml2.h"
using namespace tinyxml2;
Expand Down Expand Up @@ -165,21 +162,21 @@ namespace shellanything
info.lpFile = pathW.c_str();

//Print execute values in the logs
LOG(INFO) << "Path: " << path;
SA_LOG(INFO) << "Path: " << path;
if (!verb.empty())
{
info.lpVerb = verbW.c_str(); // Verb
LOG(INFO) << "Verb: " << verb;
SA_LOG(INFO) << "Verb: " << verb;
}
if (!arguments.empty())
{
info.lpParameters = argumentsW.c_str(); // Arguments
LOG(INFO) << "Arguments: " << arguments;
SA_LOG(INFO) << "Arguments: " << arguments;
}
if (!basedir.empty())
{
info.lpDirectory = basedirW.c_str(); // Default directory
LOG(INFO) << "Basedir: " << basedir;
SA_LOG(INFO) << "Basedir: " << basedir;
}

//Execute and get the pid
Expand All @@ -191,7 +188,7 @@ namespace shellanything
success = (pId != ra::process::INVALID_PROCESS_ID);
if (success)
{
LOG(INFO) << "Process created. PID=" << pId;
SA_LOG(INFO) << "Process created. PID=" << pId;
}

return success;
Expand Down Expand Up @@ -238,23 +235,23 @@ namespace shellanything
//warn the user if basedir was modified
if (basedir_missing && !basedir.empty())
{
LOG(INFO) << "Warning: 'basedir' not specified. Setting basedir to '" << basedir << "'.";
SA_LOG(INFO) << "Warning: 'basedir' not specified. Setting basedir to '" << basedir << "'.";
}

if (basedir.empty())
{
LOG(WARNING) << "attribute 'basedir' not specified.";
SA_LOG(WARNING) << "attribute 'basedir' not specified.";
}

//Print execute values in the logs
LOG(INFO) << "Path: " << path;
SA_LOG(INFO) << "Path: " << path;
if (!arguments.empty())
{
LOG(INFO) << "Arguments: " << arguments;
SA_LOG(INFO) << "Arguments: " << arguments;
}
if (!basedir.empty())
{
LOG(INFO) << "Basedir: " << basedir;
SA_LOG(INFO) << "Basedir: " << basedir;
}

//Execute and get the pid
Expand All @@ -271,7 +268,7 @@ namespace shellanything
bool success = (pId != ra::process::INVALID_PROCESS_ID);
if (success)
{
LOG(INFO) << "Process created. PID=" << pId;
SA_LOG(INFO) << "Process created. PID=" << pId;
}

return success;
Expand Down
14 changes: 5 additions & 9 deletions src/core/ActionFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
#include "rapidassist/unicode.h"
#include "PropertyManager.h"
#include "ObjectFactory.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 )
#include "LoggerHelper.h"

#include "tinyxml2.h"
using namespace tinyxml2;
Expand Down Expand Up @@ -125,7 +121,7 @@ namespace shellanything
const std::string encoding = pmgr.Expand(mEncoding);

//debug
LOG(INFO) << "Writing file '" << path << "'.";
SA_LOG(INFO) << "Writing file '" << path << "'.";

//validate encoding
const std::string tmp = ra::strings::Uppercase(encoding);
Expand All @@ -134,7 +130,7 @@ namespace shellanything
bool is_utf8 = (tmp == "UTF-8" || tmp == "UTF8");
if (!is_ansi && !is_unicode && !is_utf8)
{
LOG(ERROR) << "Unknown encoding attribute '" << encoding << "'.";
SA_LOG(ERROR) << "Unknown encoding attribute '" << encoding << "'.";
return false;
}

Expand All @@ -158,13 +154,13 @@ namespace shellanything
write_ok = ra::filesystem::WriteFileUtf8(path, text);
if (!write_ok)
{
LOG(ERROR) << "Failed writing content to file '" << path << "'.";
SA_LOG(ERROR) << "Failed writing content to file '" << path << "'.";
return false;
}

//get write size
uint32_t write_size = ra::filesystem::GetFileSizeUtf8(path.c_str());
LOG(INFO) << "Wrote " << write_size << " bytes to file '" << path << "'.";
SA_LOG(INFO) << "Wrote " << write_size << " bytes to file '" << path << "'.";

return true;
}
Expand Down
10 changes: 3 additions & 7 deletions src/core/ActionMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@
#include "rapidassist/strings.h"
#include "rapidassist/unicode.h"
#include "ObjectFactory.h"
#include "LoggerHelper.h"

#include "Windows.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 )

#include "tinyxml2.h"
using namespace tinyxml2;

Expand Down Expand Up @@ -131,7 +127,7 @@ namespace shellanything
std::wstring caption_utf16 = ra::unicode::Utf8ToUnicode(caption);

//debug
LOG(INFO) << "Message, caption: '" << caption << "', title: '" << title << "'.";
SA_LOG(INFO) << "Message, caption: '" << caption << "', title: '" << title << "'.";

//validate icon
UINT icon_flags = MB_OK;
Expand All @@ -151,7 +147,7 @@ namespace shellanything
}
else
{
LOG(ERROR) << "Unknown icon attribute '" << icon << "'.";
SA_LOG(ERROR) << "Unknown icon attribute '" << icon << "'.";
return false;
}

Expand Down
14 changes: 5 additions & 9 deletions src/core/ActionOpen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
#include "rapidassist/unicode.h"
#include "PropertyManager.h"
#include "ObjectFactory.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 )
#include "LoggerHelper.h"

//#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <Windows.h>
Expand Down Expand Up @@ -141,15 +137,15 @@ namespace shellanything
//is path a file?
if (ra::filesystem::FileExistsUtf8(path.c_str()))
{
LOG(INFO) << "Open file '" << path << "'.";
SA_LOG(INFO) << "Open file '" << path << "'.";
uint32_t pId = ra::process::OpenDocumentUtf8(path);
return pId != ra::process::INVALID_PROCESS_ID;
}

//is path a directory?
if (ra::filesystem::DirectoryExistsUtf8(path.c_str()))
{
LOG(INFO) << "Open directory '" << path << "'.";
SA_LOG(INFO) << "Open directory '" << path << "'.";
bool success = OpenPathGeneric(path);
return success;
}
Expand All @@ -158,12 +154,12 @@ namespace shellanything
std::wstring wide_path = ra::unicode::Utf8ToUnicode(path);
if (IsValidURL(NULL, wide_path.c_str(), 0) == S_OK)
{
LOG(INFO) << "Open url '" << path << "'.";
SA_LOG(INFO) << "Open url '" << path << "'.";
bool success = OpenPathGeneric(path);
return success;
}

LOG(ERROR) << "Unable to open '" << path << "'.";
SA_LOG(ERROR) << "Unable to open '" << path << "'.";
return false; //file not found
}

Expand Down
16 changes: 6 additions & 10 deletions src/core/ActionPrompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
#include "rapidassist/strings.h"
#include "rapidassist/unicode.h"
#include "ObjectFactory.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 )
#include "LoggerHelper.h"

#include "tinyxml2.h"
using namespace tinyxml2;
Expand Down Expand Up @@ -171,14 +167,14 @@ namespace shellanything
std::wstring caption_utf16 = ra::unicode::Utf8ToUnicode(caption);

//debug
LOG(INFO) << "Prompt: '" << title << "' ?";
SA_LOG(INFO) << "Prompt: '" << title << "' ?";

if (IsOkQuestion())
{
int result = MessageBoxW(parent_window, title_utf16.c_str(), caption_utf16.c_str(), MB_OK | MB_ICONINFORMATION);
if (result == IDCANCEL)
{
LOG(INFO) << "Prompt: user has cancelled the action.";
SA_LOG(INFO) << "Prompt: user has cancelled the action.";
return false;
}
}
Expand All @@ -195,7 +191,7 @@ namespace shellanything
break;
default:
case IDCANCEL:
LOG(INFO) << "Prompt: user has cancelled the action.";
SA_LOG(INFO) << "Prompt: user has cancelled the action.";
return false;
};
}
Expand All @@ -206,7 +202,7 @@ namespace shellanything
bool result = box.DoModal(caption_utf16, title_utf16);
if (!result)
{
LOG(INFO) << "Prompt: user has cancelled the action.";
SA_LOG(INFO) << "Prompt: user has cancelled the action.";
return false;
}

Expand All @@ -216,7 +212,7 @@ namespace shellanything
}

//update the property
LOG(INFO) << "Prompt: setting property '" << name << "' to value '" << answer << "'.";
SA_LOG(INFO) << "Prompt: setting property '" << name << "' to value '" << answer << "'.";
pmgr.SetProperty(name, answer);

return true;
Expand Down
Loading

0 comments on commit 4984c0d

Please sign in to comment.