Comments (12)
That would be a breaking change to any existing calls to information
that use those types. The only real option that comes to mind is to use static_cast<int>(__LINE__)
instead of just __LINE__
in the logger macros.
from poco.
Are you running into this issue with /ZI
in Debug? #2913 (comment)
from poco.
Are you running into this issue with
/ZI
in Debug? #2913 (comment)
Yes, you are right !
What about add some methods like
void information(const std::string& msg, const char* file, int line);
void information(const std::string& msg, const char* file, long int line); // new method to add
to fix the problem ?
from poco.
Hi!
What do you think about replacing method
void information(const std::string& msg, const char* file, int line);
with
template<typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
void information(const std::string& msg, const char* file, T line);
?
IMO this isn't breaking change
from poco.
@bas524 that looks like it should work
from poco.
@siren186, can you help me to set correct compiler options? I want to verify my changes in godbolt, but I can't get described behavour when __LINE__
is long
link with sample code
from poco.
IMO this isn't breaking change
Opinions aside, this is a breaking change. Using a template doesn't change the output. The same thing would happen with just void information(const std::string& msg, const char* file, long line)
. See this godbolt for a comparison: https://godbolt.org/z/v9hGsjd8s.
Any calls to the parameter pack version of information
such as information("%s:%d", "127.0.0.1", 5000L)
would be broken.
from poco.
@andrewauclair , I think that I found another good way to resolve the problem without templates
I fix type of __LINE__
with decltype and use this type for declaration
namespace Poco {
using LineNumber = decltype(__LINE__);
}
and then
void log(const std::string& text, Message::Priority prio, const char* file, LineNumber line);
from poco.
That would cause the same issue. Although it would only cause the issue for when the type of __LINE__
is long
. I'm also not sure that would actually work if Poco was compiled without ZI
but the application was.
The ultimate (but sadly still breaking) change would be to separate the log functions that takes file and line from the other log functions. I've wanted to add some optional C++20 logging with std::source_location
for a while as well.
from poco.
@siren186, can you help me to set correct compiler options? I want to verify my changes in godbolt, but I can't get described behavour when
__LINE__
is long link with sample code
It compiled with errors.
@andrewauclair , I think that I found another good way to resolve the problem without templates I fix type of
__LINE__
with decltype and use this type for declarationnamespace Poco { using LineNumber = decltype(__LINE__); }and then
void log(const std::string& text, Message::Priority prio, const char* file, LineNumber line);
It works well !!!
from poco.
@andrewauclair , I think that I found another good way to resolve the problem without templates I fix type of
__LINE__
with decltype and use this type for declarationnamespace Poco { using LineNumber = decltype(__LINE__); }and then
void log(const std::string& text, Message::Priority prio, const char* file, LineNumber line);
IMO this is the most elegant solution because the type for the line number is derived from the compiler/platform.
from poco.
Here's what I think would be a good compromise. A breaking change is required to properly account for long
__LINE__
and the current logging functions that log file and line number interfere with the variadic template versions of the functions. It would be good to separate these into different functions. To make sure the breaking change is clear, we can mark the existing log function with file and line as deleted. Code then can be migrated to the new logWithLocation
and the deleted version can be removed after a release or two. This would allow using the variadic template form with those arguments.
As a bonus, we can define a version of logWithVersion
that uses the new std::source_location
if the header is available. The actual check for this include would be a lot messier than this, but this is just an example. This can technically be done with the variadic template form as well using deduction guides to allow the proper calling of the function.
Godbolt for this code: https://godbolt.org/z/rM1T3d5qa
#include <iostream>
#include <string>
#include <format>
#if __has_include(<source_location>)
#include <source_location>
#endif
struct Logger {
// delete the existing log function with file and line to make the breaking change obvious
void log(const std::string& msg, const char* file, int line) = delete;
// add a new logging function with a different name to prevent confusion with the variadic template version
void logWithLocation(const std::string& msg, const char* file, decltype(__LINE__) line) {
std::cout << file << ":" << line << ": " << msg << '\n';
}
// new log function with location using the C++20 std::source_location for information
#if __has_include(<source_location>)
void logWithLocation(const std::string& msg, std::source_location location = std::source_location::current()) {
std::cout << location.file_name() << '('
<< location.line() << ':'
<< location.column() << ") `"
<< location.function_name() << ": " << msg << '\n';
}
#endif
template<typename T, typename... Args>
void log (const std::string& format, T t, Args... args) {
std::cout << std::vformat(format, std::make_format_args(t, args...)) << '\n';
}
};
int main()
{
Logger logger;
logger.logWithLocation("failed here", __FILE__, __LINE__);
logger.logWithLocation("failed again");
logger.log("{}:{}", "127.0.0.1", 5000L);
}
/app/example.cpp:38: failed here
/app/example.cpp(39:27) `int main(): failed again
127.0.0.1:5000
from poco.
Related Issues (20)
- ServerApplication waitForTerminationRequest terminate HOT 1
- Poco::ClassLoader will crashed when DLL and EXE not use MD/MDd RunTime-Library HOT 6
- Configurable or uniform chunk size in transfer encoded responses.
- Overriding SocketReactor::run() is not reasonably possible HOT 1
- NestedDiagnosticContext crashed in multi-thread environment
- Some of icompare overloads are error prone HOT 1
- ServerApplication has no pidfile option on windows
- Causing websocket to disconnect and the client not receiving any messages
- Poco::Path::forDirectory("C:") throws if the path is disk-letter only
- Poco::FileStream std::fstream HOT 3
- Process::launch to execute tail -n command, when n > 100 , wait() func while never return HOT 1
- Building on Windows and Integrating to UE5 gives PocoFoundation.lib error HOT 4
- Serving a Static Web Page and NTDDLL Error
- I met this Error [ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine]
- qnx build error on 1.13.3 release:_NTO_THREAD_NAME_MAX was not declared and tName was not declared HOT 1
- Util::IniFileConfiguration of an ecrypted stream (Crypto::CryptoInputStream) using wrong password, hangs
- Poco::UUID/UUIDGenerator: add support for Version 7 UUIDs
- POCO 1.13.3 Crypto_vs170.vcxproj build fails when using external openssl
- Update of libpng and zlib in component PDF
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from poco.