mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-10 03:18:55 +02:00
[logging] USER null fallback (#3021)
If `USER` was unset, logging would crash immediately. `USER` is *not* a guaranteed variable, so to get around this we add a null fallback and also prefer `LOGNAME`, which is "standard" on POSIX systems (yet half the time isn't set because fuck me I guess) Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3021 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: Maufeat <sahyno1996@gmail.com>
This commit is contained in:
parent
2e4ee8d9a4
commit
91d41d1c34
1 changed files with 14 additions and 4 deletions
|
|
@ -112,10 +112,20 @@ public:
|
|||
// This must be a static otherwise it would get checked on EVERY
|
||||
// instance of logging an entry...
|
||||
static std::string username = []() -> std::string {
|
||||
auto* s = getenv("USER");
|
||||
if (s == nullptr)
|
||||
s = getenv("USERNAME");
|
||||
return std::string{s};
|
||||
// in order of precedence
|
||||
// LOGNAME usually works on UNIX, USERNAME on Windows
|
||||
// Some UNIX systems suck and don't use LOGNAME so we also
|
||||
// need USER :(
|
||||
for (auto const var : {
|
||||
"LOGNAME",
|
||||
"USERNAME",
|
||||
"USER",
|
||||
}) {
|
||||
if (auto const s = getenv(var); s != nullptr)
|
||||
return std::string{s};
|
||||
}
|
||||
|
||||
return std::string{};
|
||||
}();
|
||||
if (!username.empty())
|
||||
boost::replace_all(message, username, "user");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue