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

4847 logger singleton 3.1 #5119

Merged
merged 12 commits into from Mar 27, 2024
Merged

4847 logger singleton 3.1 #5119

merged 12 commits into from Mar 27, 2024

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Mar 22, 2024

Pull request overview

I just want CI to run on it to I'm targeting develop for now, but really this is just a modification of #5110

Pull Request Author

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

kbenne and others added 6 commits March 22, 2024 11:44
Previously, we used the openstudio::Singleton template to create the
singleton named Logger. This implementation suffered a bug described
in #4847, where the singleton was not global across the ScriptEngine DLL
boundary.

This change is a non templated implementation of Logger. The design is
identical to openstudio::Singleton<LoggerSingleton>, but does not suffer
the non-global issue.

ref #4847
UtilitiesAPI.hpp needs to be included by SWIG so that the correct
declspecs are used for the global logger. Previously, UTILITIES_API was
just #define OPENSTUDIO_API, therefore the dll export decorator was not
used.
@jmarrec jmarrec added the Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. label Mar 22, 2024
@jmarrec jmarrec requested a review from kbenne March 22, 2024 13:12
Comment on lines 11 to 12
#include "Compare.hpp" // NOTE that this this is not needed for this header but so many compilation errors if I omit it
// since other files transitively use Compare
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An unfortunate discovery. Cleaning up ours headers would be good, but that's not what I'm trying to achieve here.


private:
static std::shared_ptr<LoggerImpl> obj;
std::shared_ptr<detail::Logger_Impl> m_impl;
Copy link
Collaborator Author

@jmarrec jmarrec Mar 25, 2024

Choose a reason for hiding this comment

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

Given that the Logger is a Meyers singleton, I'm not sure whether the Logger_Impl class is really needed at all. But it feels familiar at least, and can allow us to shorten the public includes.

The dowside is that there's an extra method call for each (the forward to impl)

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, I don't think we really need an Impl at all.

Comment on lines 136 to 140
Logger::Logger() : m_impl(std::shared_ptr<detail::Logger_Impl>(new detail::Logger_Impl())) {}

Logger& Logger::instance() {
static Logger instance;
return instance;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Private constructor, and public ::instance()

@jmarrec jmarrec self-assigned this Mar 27, 2024
@jmarrec jmarrec marked this pull request as ready for review March 27, 2024 16:14
@jmarrec jmarrec merged commit f6310d8 into develop Mar 27, 2024
2 of 6 checks passed
@jmarrec jmarrec deleted the 4847_LoggerSingleton_3.1 branch March 27, 2024 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants