Skip to content

Commit

Permalink
log: add tracing level
Browse files Browse the repository at this point in the history
  • Loading branch information
janmojzis committed Dec 20, 2023
1 parent 3a8da69 commit 97083ca
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
5 changes: 4 additions & 1 deletion tinyssh/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The 'log' library also supports syslog.

static const char *logtext = "x";
static char logstring[9] = "________";
static int loglevel = 1;
int loglevel = 1;

static int logflagfnln = 1;
static int logflagsyslog = 0;
Expand Down Expand Up @@ -130,6 +130,9 @@ void log_9_(
case 3:
m = "debug";
break;
case 4:
m = "tracing";
break;
default:
m = "unknown";
break;
Expand Down
53 changes: 48 additions & 5 deletions tinyssh/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
extern void log_init(int, const char *, int, int);
extern char *log_string(void);

extern int loglevel;

extern void log_9_(
int,
int,
Expand All @@ -20,7 +22,12 @@ extern void log_9_(
const char *);

/* usage */
#define log_u9(a,b,c,d,e,f,g,h,i) log_9_(0,1,__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_u(a,b,c,d,e,f,g,h,i,j,k) \
do { \
if (loglevel < 0) break; \
log_9_(0,1,a,b,c,d,e,f,g,h,i,j,k); \
} while (0)
#define log_u9(a,b,c,d,e,f,g,h,i) log_u(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_u8(a,b,c,d,e,f,g,h) log_u9(a,b,c,d,e,f,g,h,0)
#define log_u7(a,b,c,d,e,f,g) log_u8(a,b,c,d,e,f,g,0)
#define log_u6(a,b,c,d,e,f) log_u7(a,b,c,d,e,f,0)
Expand All @@ -31,7 +38,12 @@ extern void log_9_(
#define log_u1(a) log_u2(a,0)

/* fatal */
#define log_f9(a,b,c,d,e,f,g,h,i) log_9_(1,0,__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_f(a,b,c,d,e,f,g,h,i,j,k) \
do { \
if (loglevel < 1) break; \
log_9_(1,0,a,b,c,d,e,f,g,h,i,j,k); \
} while (0)
#define log_f9(a,b,c,d,e,f,g,h,i) log_f(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_f8(a,b,c,d,e,f,g,h) log_f9(a,b,c,d,e,f,g,h,0)
#define log_f7(a,b,c,d,e,f,g) log_f8(a,b,c,d,e,f,g,0)
#define log_f6(a,b,c,d,e,f) log_f7(a,b,c,d,e,f,0)
Expand All @@ -42,7 +54,12 @@ extern void log_9_(
#define log_f1(a) log_f2(a,0)

/* warning */
#define log_w9(a,b,c,d,e,f,g,h,i) log_9_(2,0,__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_w(a,b,c,d,e,f,g,h,i,j,k) \
do { \
if (loglevel < 2) break; \
log_9_(2,0,a,b,c,d,e,f,g,h,i,j,k); \
} while (0)
#define log_w9(a,b,c,d,e,f,g,h,i) log_w(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_w8(a,b,c,d,e,f,g,h) log_w9(a,b,c,d,e,f,g,h,0)
#define log_w7(a,b,c,d,e,f,g) log_w8(a,b,c,d,e,f,g,0)
#define log_w6(a,b,c,d,e,f) log_w7(a,b,c,d,e,f,0)
Expand All @@ -53,7 +70,12 @@ extern void log_9_(
#define log_w1(a) log_w2(a,0)

/* info */
#define log_i9(a,b,c,d,e,f,g,h,i) log_9_(2,1,__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_i(a,b,c,d,e,f,g,h,i,j,k) \
do { \
if (loglevel < 2) break; \
log_9_(2,1,a,b,c,d,e,f,g,h,i,j,k); \
} while (0)
#define log_i9(a,b,c,d,e,f,g,h,i) log_i(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_i8(a,b,c,d,e,f,g,h) log_i9(a,b,c,d,e,f,g,h,0)
#define log_i7(a,b,c,d,e,f,g) log_i8(a,b,c,d,e,f,g,0)
#define log_i6(a,b,c,d,e,f) log_i7(a,b,c,d,e,f,0)
Expand All @@ -64,7 +86,12 @@ extern void log_9_(
#define log_i1(a) log_i2(a,0)

/* debug */
#define log_d9(a,b,c,d,e,f,g,h,i) log_9_(3,1,__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_d(a,b,c,d,e,f,g,h,i,j,k) \
do { \
if (loglevel < 3) break; \
log_9_(3,1,a,b,c,d,e,f,g,h,i,j,k); \
} while (0)
#define log_d9(a,b,c,d,e,f,g,h,i) log_d(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_d8(a,b,c,d,e,f,g,h) log_d9(a,b,c,d,e,f,g,h,0)
#define log_d7(a,b,c,d,e,f,g) log_d8(a,b,c,d,e,f,g,0)
#define log_d6(a,b,c,d,e,f) log_d7(a,b,c,d,e,f,0)
Expand All @@ -74,4 +101,20 @@ extern void log_9_(
#define log_d2(a,b) log_d3(a,b,0)
#define log_d1(a) log_d2(a,0)

/* tracing */
#define log_t(a,b,c,d,e,f,g,h,i,j,k) \
do { \
if (loglevel < 4) break; \
log_9_(4,1,a,b,c,d,e,f,g,h,i,j,k); \
} while (0)
#define log_t9(a,b,c,d,e,f,g,h,i) log_t(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i)
#define log_t8(a,b,c,d,e,f,g,h) log_t9(a,b,c,d,e,f,g,h,0)
#define log_t7(a,b,c,d,e,f,g) log_t8(a,b,c,d,e,f,g,0)
#define log_t6(a,b,c,d,e,f) log_t7(a,b,c,d,e,f,0)
#define log_t5(a,b,c,d,e) log_t6(a,b,c,d,e,0)
#define log_t4(a,b,c,d) log_t5(a,b,c,d,0)
#define log_t3(a,b,c) log_t4(a,b,c,0)
#define log_t2(a,b) log_t3(a,b,0)
#define log_t1(a) log_t2(a,0)

#endif
3 changes: 1 addition & 2 deletions tinyssh/main_tinysshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int main_tinysshd(int argc, char **argv, const char *binaryname) {
while (*++x) {
if (*x == 'q') { flagverbose = 0; continue; }
if (*x == 'Q') { flagverbose = 1; continue; }
if (*x == 'v') { if (flagverbose >= 2) flagverbose = 3; else flagverbose = 2; continue; }
if (*x == 'v') { ++flagverbose; if (flagverbose >= 4) flagverbose = 4; continue; }
if (*x == 'o') { cryptotypeselected |= sshcrypto_TYPEOLDCRYPTO; continue; }
if (*x == 'O') { cryptotypeselected &= ~sshcrypto_TYPEOLDCRYPTO; continue; }
if (*x == 's') { cryptotypeselected |= sshcrypto_TYPENEWCRYPTO; continue; }
Expand Down Expand Up @@ -218,7 +218,6 @@ int main_tinysshd(int argc, char **argv, const char *binaryname) {
watchtochild = watchfromchild1 = watchfromchild2 = 0;
watchselfpipe = 0;
}

else {
if (watch0) if (!watch0->revents) watch0 = 0;
if (watch1) if (!watch1->revents) watch1 = 0;
Expand Down

0 comments on commit 97083ca

Please sign in to comment.