Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log to file as well as immediate window #215

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Sophist-UK
Copy link
Contributor

This PR adds functionality to write the same log messages to a file as well as to the VBA immediate window.

This PR adds functionality to write the same log messages to a
file as well as to the VBA immediate window.
For performance reasons the log file is held open unless the project is
reset.

This commit adds a method to close the log file in order to allow
programmatic changes to the log file location.
Public Sub without args are available to run as a macro from the Outlook
UI.
Avoid having separate Debug.Print statements in order to print debugging
regardless of EnableLogging or file logging.

FileOpenError:
Debug.Print "ERROR: Unable to open logfile '" & LogFile & "' for Append Write: Error " & Err.Number & ": " & Err.Description
LogFileNumber = -100
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is not to issue excessive numbers of these errors to the immediate window - but upon reflection I am not sure this is such a good idea - or perhaps only if normal EnableLogging is true.

@Sophist-UK
Copy link
Contributor Author

On reflection, I wonder whether the Debug.Print logic should be included in the LogWrite routine.

Also, I wonder if we should write the time-stamp to the immediate window also - and if so whether this should be through a separate boolean Public property.

@timhall
Copy link
Member

timhall commented Apr 5, 2016

Hi @Sophist-UK rather than include the file logging with VBA-Web, I'd recommend replacing the current logging with VBA-Log and then creating a standalone file logger that can be used with it. Also, I know you've had some qualms with Application.Run (rightfully so), so feel free to submit a PR to add/switch to CallByName

Example:

Dim FileLogger = New FileLog
Logger.LogFile = "..."

WebHelpers.LogInstance = FileLogger
WebHelpers.LogThreshold = 4

' -> CallByName FileLogger, "Log", vbMethod, Level, Message, From

@timhall
Copy link
Member

timhall commented Apr 5, 2016

Here's the related issue: VBA-tools/VBA-Log#1

@Sophist-UK
Copy link
Contributor Author

In principle I agree, however VBA-Log uses Application.Run for the callbacks which makes it inelligent but also incompatible with some Office applications. And that would have a knock on effect on VBA-Web compatibility.

BUT ... if we can merge the functionality i.e. to provide file logging as a standard part of VBA-Log which does not rely on callbacks, then we could have the best of both worlds.

That said, a change to VBA-Log would seem to be something for VBA-Web v5, and o perhaps we can include these changes in the interim in v4.

@Sophist-UK
Copy link
Contributor Author

BTW, I cannot believe what VBA-Web has enabled me to achieve in Outlook. Happy to tell you offline if you want to correspond privately. (sophist at sodalis dot co dot uk)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants