Skip to content

Commit

Permalink
Merge pull request #1704 from Expensify/main
Browse files Browse the repository at this point in the history
Update expensify_prod branch
  • Loading branch information
madmax330 authored Apr 29, 2024
2 parents 73dbdad + dbfd2d6 commit 1d49298
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
25 changes: 23 additions & 2 deletions libstuff/SLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,33 @@
// Global logging state shared between all threads
atomic<int> _g_SLogMask(LOG_INFO);

void SLogStackTrace() {
void SLogStackTrace(int level) {
// Output the symbols to the log
void* callstack[100];
int depth = backtrace(callstack, 100);
vector<string> stack = SGetCallstack(depth, callstack);
for (const auto& frame : stack) {
SWARN(frame);
switch (level) {
case LOG_DEBUG:
SDEBUG(frame);
break;
case LOG_INFO:
SINFO(frame);
break;
case LOG_NOTICE:
SHMMM(frame);
break;
case LOG_WARNING:
SWARN(frame);
break;
case LOG_ALERT:
SALERT(frame);
break;
case LOG_ERR:
SERROR(frame);
break;
default:
break;
}
}
}
18 changes: 11 additions & 7 deletions libstuff/libstuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,14 @@ class SString : public string {
typedef map<string, SString, STableComp> STable;

// An SException is an exception class that can represent an HTTP-like response, with a method line, headers, and a
// body. The STHROW and STHROW_STACK macros will create an SException that logs it's file and line of creation, and
// optionally, a stack trace at the same time. They can take, 1, 2, or all 3 of the components of an HTTP response
// as arguments.
#define STHROW(...) throw SException(__FILE__, __LINE__, false, __VA_ARGS__)
// body. The STHROW and STHROW_STACK macros will create an SException that logs it's file, line of creation, and
// a stack trace at the same time. They can take, 1, 2, or all 3 of the components of an HTTP response as arguments.
#define STHROW(...) \
do { \
SLogStackTrace(LOG_DEBUG); \
throw SException(__FILE__, __LINE__, false, __VA_ARGS__); \
} while (false)

#define STHROW_STACK(...) throw SException(__FILE__, __LINE__, true, __VA_ARGS__)
class SException : public exception {
private:
Expand Down Expand Up @@ -217,7 +221,7 @@ extern atomic<int> _g_SLogMask;
void SLogLevel(int level);

// Stack trace logging
void SLogStackTrace();
void SLogStackTrace(int level = LOG_WARNING);

// This is a drop-in replacement for syslog that directly logs to `/run/systemd/journal/syslog` bypassing journald.
void SSyslogSocketDirect(int priority, const char* format, ...);
Expand Down Expand Up @@ -368,7 +372,7 @@ template <class A> inline bool SContains(const set<A>& valueList, const A& value

bool SContains(const list<string>& valueList, const char* value);
bool SContains(const string& haystack, const string& needle);
bool SContains(const string& haystack, char needle);
bool SContains(const string& haystack, char needle);
bool SContains(const STable& nameValueMap, const string& name);

bool SIsValidSQLiteDateModifier(const string& modifier);
Expand All @@ -378,7 +382,7 @@ bool SIEquals(const string& lhs, const string& rhs);
bool SIContains(const string& haystack, const string& needle);
bool SStartsWith(const string& haystack, const string& needle);
bool SStartsWith(const char* haystack, size_t haystackSize, const char* needle, size_t needleSize);
bool SEndsWith(const string& haystack, const string& needle);
bool SEndsWith(const string& haystack, const string& needle);
bool SConstantTimeEquals(const string& secret, const string& userInput);
bool SConstantTimeIEquals(const string& secret, const string& userInput);

Expand Down

0 comments on commit 1d49298

Please sign in to comment.