Skip to content

Commit 3db95a7

Browse files
authored
Merge pull request #163 from end2endzone/feature-issue109
Merge branch feature-issue109.
2 parents 4964dbd + 7f0a649 commit 3db95a7

48 files changed

Lines changed: 2336 additions & 110 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Changes for 0.10.0
22

33
* Deprecated support for icons with negative resource id.
4+
* Fixed issue #109: Implement default and verbose logging.
45
* Fixed issue #150: ico icon (that do not specifically force index=0) are not working.
56
* Fixed issue #155: Drop support for loading icons from a resource id (icons with a negative index smaller than -1).
67
* Fixed issue #157: Compilation fails on Github Action: `fatal error C1083: Cannot open include file: 'atlbase.h': No such file or directory`.

UserManual.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ This manual includes a description of the system functionalities and capabilitie
4040
* [Setting properties](#setting-properties)
4141
* [Property expansion](#property-expansion)
4242
* [Using properties](#using-properties)
43-
* [Environment variables](#environment-variables)
43+
* [Environment variables properties](#environment-variables-properties)
4444
* [Live properties](#live-properties)
4545
* [Selection-based properties](#selection-based-properties)
4646
* [Multi-selection-based properties](#multi-selection-based-properties)
4747
* [Fixed properties](#fixed-properties)
4848
* [Default properties](#default-properties)
49+
* [Environment variables](#environment-variables)
4950
* [Plugins](#plugins)
5051
* [Plugin overview](#plugin-overview)
5152
* [C API](#c-api)
@@ -1530,7 +1531,7 @@ For instance, if one wants to implement 2 menus (called 'A' and 'B') and only sh
15301531

15311532

15321533

1533-
## Environment variables ##
1534+
## Environment variables properties ##
15341535

15351536
The list of environment variables is available through the property system.
15361537

@@ -1776,6 +1777,25 @@ For example, the following would define `services.wce.command.start` and `servic
17761777

17771778

17781779

1780+
# Environment variables #
1781+
1782+
ShellAnything default startup behavior can be modified by setting specific pre-defined environment variables. Some features or configuration options can also be enabled or disabled through environment variables. For example, one can define an environment variables to enable verbose logging.
1783+
1784+
Most of the time, if a feature can be enabled/disabled from an environment variable and/or a property, the environment variable have priority over internal properties.
1785+
1786+
Most environment variables are detected when the application starts. After application startup, if you modify an environment variable you have to log off from windows and log in again for the changes to take effect.
1787+
1788+
All ShellAnything environment variables names are prefixed with `SA_`.
1789+
1790+
The following table defines the list of pre-defined environment variables for ShellAnything:
1791+
1792+
| Name | Description |
1793+
|--------------------------------|--------------------------------------------------------------------------------------------------------------------|
1794+
| SA_OPTION_LOGGING_VERBOSE | Enables [verbose logging](#verbose-logging) when set to a value that evaluates to [true](#istrue-attribute). |
1795+
1796+
1797+
1798+
17791799
# Plugins #
17801800

17811801

@@ -2553,6 +2573,22 @@ There are no plan for keeping the log files for more than 5 days.
25532573

25542574

25552575

2576+
### Verbose logging ###
2577+
2578+
The application has a verbose logging mode. When enabled, the application will log additional details. This mode should be disabled by default. It should be temporary enabled because log files will likely contain sensitive information.
2579+
2580+
Verbose mode is highly beneficial for debugging because it provides detailed information about the execution of the program. It allows you to see each step and print out intermediate values, helping you identify where things might be going wrong. For example, it is useful for diagnosing the reason for [Visibility / Validity](#visibility--validity) check failures.
2581+
2582+
The verbose mode can be enabled (or disabled) with the following option :
2583+
* Setting property `system.logging.verbose` to a value that evaluates to [true](#istrue-attribute) or [false](#isfalse-attribute).
2584+
* Setting environment variable `SA_OPTION_LOGGING_VERBOSE` to a value that evaluates to [true](#istrue-attribute) or [false](#isfalse-attribute).
2585+
2586+
If both options are specified, the environment variable has priority.
2587+
2588+
If no option is specified, verbose mode is disabled.
2589+
2590+
2591+
25562592
## Missing ampersand character (`&`) in menus ##
25572593

25582594
One might be puzzled as to why his menus do not display ampersand character (`&`) properly.

include/shellanything/sa_logging.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifndef SA_API_LOGGING_H
2626
#define SA_API_LOGGING_H
2727

28+
#include "shellanything/sa_types.h"
2829
#include "shellanything/sa_enums.h"
2930

3031
#ifdef __cplusplus
@@ -34,6 +35,12 @@ extern "C" {
3435
#endif
3536
#endif
3637

38+
/// <summary>
39+
/// Check if verbose logging is enabled.
40+
/// </summary>
41+
/// <returns>Return 1 if the verbose logging feature is enabled. Returns 0 otherwise.</returns>
42+
sa_boolean sa_logging_is_verbose();
43+
3744
/// <summary>
3845
/// Log a custom message in logs.
3946
/// </summary>

resources/configurations/shellanything.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,34 @@
103103
<open path="https://github.com/end2endzone/ShellAnything/releases/latest" />
104104
</actions>
105105
</menu>
106+
</menu>
107+
108+
<menu name="Verbose logging">
109+
<icon path="C:\Windows\system32\shell32.dll" index="70" />
106110

111+
<menu name="Verbose logging is ENABLED">
112+
<visibility istrue="${system.logging.verbose}" />
113+
</menu>
114+
<menu name="Verbose logging is DISABLED">
115+
<visibility istrue="${system.logging.verbose}" inverse="istrue" />
116+
</menu>
117+
<menu separator="true" />
118+
<menu name="Enable">
119+
<icon path="C:\Windows\system32\shell32.dll" index="302" />
120+
<actions>
121+
<property name="system.logging.verbose" value="${system.true}" />
122+
</actions>
123+
</menu>
124+
<menu name="Disable">
125+
<icon path="C:\Windows\system32\shell32.dll" index="109" />
126+
<actions>
127+
<property name="system.logging.verbose" value="${system.false}" />
128+
</actions>
129+
</menu>
107130
</menu>
108131

132+
<menu separator="true />
133+
109134
<menu name="More configurations files...">
110135
<icon path="C:\Windows\system32\shell32.dll" index="69" />
111136
<actions>

src/api/sa.api.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ EXPORTS
3636
sa_icon_set_index
3737
sa_icon_set_path
3838
sa_icon_to_immutable
39+
sa_logging_is_verbose
3940
sa_logging_print
4041
sa_logging_print_format
4142
sa_memory_alloc

src/api/sa_logging.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
#include <stdarg.h> //for ...
2828
#include <string>
2929

30+
sa_boolean sa_logging_is_verbose()
31+
{
32+
bool value = shellanything::LoggerHelper::IsVerboseLoggingEnabled();
33+
if (value)
34+
return 1;
35+
return 0;
36+
}
37+
3038
void sa_logging_print(sa_log_level_t level, const char* source_name, const char* message)
3139
{
3240
if (source_name)

src/core/ActionManager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,26 @@
2626
#include "PropertyManager.h"
2727
#include "LoggerHelper.h"
2828

29+
#include "SaUtils.h"
30+
2931
#include "rapidassist/errors.h"
3032

3133
namespace shellanything
3234
{
3335

3436
bool ActionManager::Execute(const Menu* menu, const SelectionContext& context)
3537
{
38+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
39+
sli.verbose = true;
40+
ScopeLogger logger(&sli);
41+
3642
//compute the visual menu title
3743
shellanything::PropertyManager& pmgr = shellanything::PropertyManager::GetInstance();
3844
std::string title = pmgr.Expand(menu->GetName());
3945

4046
bool success = true;
4147

42-
SA_LOG(INFO) << "Executing action(s) for menu '" << title.c_str() << "'...";
48+
SA_LOG(INFO) << "Executing action(s) for menu '" << title.c_str() << "', id=" << menu->GetCommandId() << "...";
4349

4450
//execute actions
4551
const shellanything::IAction::ActionPtrList& actions = menu->GetActions();
@@ -59,7 +65,7 @@ namespace shellanything
5965
if (dwError)
6066
{
6167
std::string error_message = ra::errors::GetErrorCodeDescription(dwError);
62-
SA_LOG(ERROR) << "Action #" << (i + 1) << " has failed: " << error_message;
68+
SA_LOG(ERROR) << "Action #" << (i + 1) << " has failed: " << ToHexString(dwError) << ", " << error_message;
6369
}
6470
else
6571
{

src/core/ActionOpen.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,19 @@ namespace shellanything
139139
{
140140
SA_LOG(INFO) << "Open file '" << path << "'.";
141141
uint32_t pId = ra::process::OpenDocumentUtf8(path);
142-
return pId != ra::process::INVALID_PROCESS_ID;
142+
bool success = (pId != ra::process::INVALID_PROCESS_ID);
143+
if (!success)
144+
SA_LOG(ERROR) << "Failed opening file '" << path << "'.";
145+
return success;
143146
}
144147

145148
//is path a directory?
146149
if (ra::filesystem::DirectoryExistsUtf8(path.c_str()))
147150
{
148151
SA_LOG(INFO) << "Open directory '" << path << "'.";
149152
bool success = OpenPathGeneric(path);
153+
if (!success)
154+
SA_LOG(ERROR) << "Failed opening directory '" << path << "'.";
150155
return success;
151156
}
152157

@@ -156,6 +161,8 @@ namespace shellanything
156161
{
157162
SA_LOG(INFO) << "Open url '" << path << "'.";
158163
bool success = OpenPathGeneric(path);
164+
if (!success)
165+
SA_LOG(ERROR) << "Failed opening URL '" << path << "'.";
159166
return success;
160167
}
161168

src/core/ActionProperty.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ namespace shellanything
259259
}
260260
}
261261

262-
// If regisrykey is specified, it has priority over value. This is required to allow setting a property to an empty value (a.k.a. value="").
262+
// If registrykey is specified, it has priority over value. This is required to allow setting a property to an empty value (a.k.a. value="").
263263
if (!registrykey.empty())
264264
{
265265
std::string tmp_value;

src/core/ActionStop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ namespace shellanything
115115

116116
bool validated = mValidator->Validate(context);
117117

118-
//update the property
118+
//log the result
119119
if (validated)
120120
SA_LOG(INFO) << "ActionStop: Validation is successful.";
121121
else

0 commit comments

Comments
 (0)