mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-21 01:42:18 +00:00
Improve log pathname trimming
This commit is contained in:
parent
59e58da2f4
commit
2f6f642a02
24
log.c
24
log.c
@ -62,22 +62,18 @@ void vlogMessage(int level, char *fmt, va_list ap)
|
||||
fprintf(stderr, "%s: %s\n", levelstr, buf);
|
||||
}
|
||||
|
||||
int build_path_len=-1;
|
||||
char *trimbuildpath(char *s)
|
||||
const char *trimbuildpath(const char *s)
|
||||
{
|
||||
if (build_path_len==-1) {
|
||||
/* Find common path prefix so that we can get rid of the build path
|
||||
when reporting file names in logs */
|
||||
int lastSlash=0;
|
||||
int i=0;
|
||||
for(i=0;i<strlen(__FILE__)&&i<strlen(s);i++)
|
||||
if (__FILE__[i]!=s[i]) break;
|
||||
else if (s[i]=='/') lastSlash=i;
|
||||
|
||||
build_path_len=lastSlash;
|
||||
/* Remove common path prefix */
|
||||
int lastsep = 0;
|
||||
int i;
|
||||
for (i = 0; __FILE__[i] && s[i]; ++i) {
|
||||
if (i && s[i - 1] == '/')
|
||||
lastsep = i;
|
||||
if (__FILE__[i] != s[i])
|
||||
break;
|
||||
}
|
||||
|
||||
return &s[build_path_len];
|
||||
return &s[lastsep];
|
||||
}
|
||||
|
||||
int setReason(char *fmt, ...)
|
||||
|
2
serval.h
2
serval.h
@ -765,8 +765,8 @@ long long debugFlagMask(const char *flagname);
|
||||
char *catv(const char *data, char *buf, size_t len);
|
||||
int dump(char *name,unsigned char *addr,int len);
|
||||
|
||||
const char *trimbuildpath(const char *s);
|
||||
|
||||
char *trimbuildpath(char *s);
|
||||
#define FATALF(F,...) do { logMessage(LOG_LEVEL_FATAL, "%s:%d:%s() " F, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); exit(-1); } while(1)
|
||||
#define FATAL(X) FATALF("%s", (X))
|
||||
#define FATAL_perror(X) FATALF("%s: %s [errno=%d]", (X), strerror(errno), errno)
|
||||
|
Loading…
x
Reference in New Issue
Block a user