-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Type safe logging #14317
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
Type safe logging #14317
Conversation
|
Any reason to move implementation of some functions from .cpp to .h? if there is no improvement (by profiler) they should remain at .cpp files (+ adding implementation to .h ends up adding unnecessary includes to the rest of the code due to include chain) |
src/server/shared/Logging/Log.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are arguments evaluated even if sLog->ShouldLog() returns false ? if so, then this is not an acceptable change due to performance reasons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted this change, my mistake.
|
could you elaborate more on the need of using shared_ptr ? |
|
@Spp- because of variadic templates i'm sure it will lead to linker errors if i put it into the .cpp file. |
src/server/shared/Utilities/Util.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will lead to random characters in front of the string.
Anyone got an idea?
|
Strange linker errors on clang:
|
d2c7d2f to
95a9b22
Compare
src/server/shared/Utilities/Format.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be put in Trinity namespace (also function naming standards...)
|
With "It will warn you if you use the wrong formatter" what exactly do you mean ? If on the other hand the exception is caught, where and how is the information about the line triggering the exception saved to fix the issue ? |
|
You are right, as i started to work on this i thought its possible to catch it at build time but its only possible to catch it at runtime because the format is read at runtime only. try
{
return mainImpl(argc, argv);
}
catch (std::exception& ex)
{The actual problem is that (for me) the WeathyException stracktrace isn't shown on crash. |
|
WEH not showing the stacktrace sounds like a bug, could you open an issue so I can look into that ? feel free to reference this PR to reproduce it. As for the log format, this is my idea of format errors handling, listed by "what I'd like to happen" on top:
The current implementation makes things worse for users who don't really care much about logs, with "always crashing" instead of "crashing sometimes". It might be worth to investigate about different ways to handle the errors/different ways to catch them at build time. |
|
If you only use printf-like format strings and OK with macros, then you can catch format type errors at compile time using the technique described in fmtlib/fmt#62 (comment). |
|
@jackpoz see: |
0dc97dc to
eed512f
Compare
* improves safety and log speed through: - variadic templates - perfect forwarding * fixes a newline in db logs * improve performance of Appender::write by using std::ostringstream && std::move
|
👍 |
|
If requested i can add type safety also to SQL query api functions like PQuey and its derivates and other functions that use still vaargs and char[] with a very high field size (to increase speed). |
|
That would be quite nice indeed |
Type safe logging (cherry picked from commit cc0c9ad) Conflicts: src/server/bnetserver/CMakeLists.txt src/server/game/Server/WorldSocketMgr.cpp src/server/shared/Logging/AppenderDB.cpp src/server/worldserver/CMakeLists.txt
|
After this applied, .gps command crashes server |
|
Post the crash/error log |
|
Researched it a little in Debug mode: Error raised trying to retrieve argument nº 17 (LANG_MAP_POSITION string requires 23 arguments) and the default is set to an arbitrary 16 in the class ArgList used in format.h, line 1053, just bump the limit a little. After doing this, I get another exception, I setted MAX_ARGS to 32. |
|
You cannot simply change a random value in a library and expect it to work... |
|
True that, maybe the maximum is enforced elsewhere, the problem is, that this library should provide same funcionality than vsprintf, rather than possibly forcing a change of those trinity_strings with more than 16 format placeholders. |
|
Already checked for this, gps string is the only case |
|
The question is: do a Log or PSensSysMsg call really need more then above 16 args? I think its not needed. @Shauren checked it yesterday too in core and db its only LANG_MAP_POSITION . EDIT: I'm on it. |
* http://stackoverflow.com/questions/4891067/weird-undefined-symbols-of-static-constants-inside-a-struct-class * http://www-01.ibm.com/support/knowledgecenter/SSGH3R_8.0.0/com.ibm.xlcpp8a.doc/language/ref/cplr038.htm%23cplr038 * closes #14463 * ref #14317 (cherry picked from commit 9b0b118) Conflicts: src/server/game/Server/WorldSocketMgr.cpp
Use Type safe variadic templates for for toplevel api functions (TC_LOG & PSendSysMsg)
It will show error messages if you use wrong formattters in logging functions ("%s" instead of "%u" for example).
Its also possible to use std::string as formatter now what makes it unnecessary to call c_str() on it.
Also there is a global Trinity::StringFormat function added that allows you to format strings in any way.
There is also the possibility to convert more vaargs to type safe variadic templates if desired (mysql query api, internal format calls)
ToDo:
-> Finished