Skip to content

Commit

Permalink
fixed logging
Browse files Browse the repository at this point in the history
  • Loading branch information
axkibe committed Nov 21, 2011
1 parent b790639 commit c669051
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
22 changes: 9 additions & 13 deletions lsyncd.c
Expand Up @@ -86,7 +86,7 @@ struct settings settings = {
.log_syslog = false, .log_syslog = false,
.log_ident = NULL, .log_ident = NULL,
.log_facility = LOG_USER, .log_facility = LOG_USER,
.log_level = 0, .log_level = LOG_NOTICE,
.nodaemon = false, .nodaemon = false,
}; };


Expand Down Expand Up @@ -211,19 +211,19 @@ check_logcat(const char *name)
{ {
struct logcat *lc; struct logcat *lc;
if (name[0] < 'A' || name[0] > 'Z') { if (name[0] < 'A' || name[0] > 'Z') {
return false; return 99;
} }
lc = logcats[name[0]-'A']; lc = logcats[name[0]-'A'];
if (!lc) { if (!lc) {
return -1; return 99;
} }
while (lc->name) { while (lc->name) {
if (!strcmp(lc->name, name)) { if (!strcmp(lc->name, name)) {
return lc->priority; return lc->priority;
} }
lc++; lc++;
} }
return -1; return 99;
} }


/** /**
Expand All @@ -235,7 +235,7 @@ add_logcat(const char *name, int priority)
{ {
struct logcat *lc; struct logcat *lc;
if (!strcmp("all", name)) { if (!strcmp("all", name)) {
settings.log_level = -1; settings.log_level = 99;
return true; return true;
} }
if (!strcmp("scarce", name)) { if (!strcmp("scarce", name)) {
Expand Down Expand Up @@ -287,10 +287,6 @@ add_logcat(const char *name, int priority)
extern void extern void
logstring0(int priority, const char *cat, const char *message) logstring0(int priority, const char *cat, const char *message)
{ {
/* in case of logall and not found category priority will be -1 */
if (priority < 0) {
priority = LOG_DEBUG;
}
if (first_time) { if (first_time) {
/* lsyncd is in intial configuration. /* lsyncd is in intial configuration.
* thus just print to normal stdout/stderr. */ * thus just print to normal stdout/stderr. */
Expand Down Expand Up @@ -767,7 +763,7 @@ l_log(lua_State *L)
cat = luaL_checkstring(L, 1); cat = luaL_checkstring(L, 1);
priority = check_logcat(cat); priority = check_logcat(cat);
/* skips filtered messages */ /* skips filtered messages */
if (priority < settings.log_level) { if (priority > settings.log_level) {
return 0; return 0;
} }


Expand Down Expand Up @@ -887,7 +883,7 @@ l_exec(lua_State *L)
} }
} }
/* writes a log message, prepares the message only if actually needed. */ /* writes a log message, prepares the message only if actually needed. */
if (check_logcat("Exec") >= settings.log_level) { if (check_logcat("Exec") <= settings.log_level) {
int i; int i;
lua_checkstack(L, lua_gettop(L) + argc * 3 + 2); lua_checkstack(L, lua_gettop(L) + argc * 3 + 2);
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
Expand Down Expand Up @@ -1794,7 +1790,7 @@ main1(int argc, char *argv[])
/* registers lsycnd core */ /* registers lsycnd core */
register_lsyncd(L); register_lsyncd(L);


if (check_logcat("Debug") >= settings.log_level) { if (check_logcat("Debug") <= settings.log_level) {
/* printlogf doesnt support %ld :-( */ /* printlogf doesnt support %ld :-( */
printf("kernels clocks_per_sec=%ld\n", clocks_per_sec); printf("kernels clocks_per_sec=%ld\n", clocks_per_sec);
} }
Expand Down Expand Up @@ -2047,7 +2043,7 @@ main1(int argc, char *argv[])
settings.log_ident = NULL; settings.log_ident = NULL;
} }
settings.log_facility = LOG_USER; settings.log_facility = LOG_USER;
settings.log_level = 0; settings.log_level = LOG_NOTICE;
settings.nodaemon = false; settings.nodaemon = false;
lua_close(L); lua_close(L);
return 0; return 0;
Expand Down
4 changes: 2 additions & 2 deletions lsyncd.h
Expand Up @@ -90,13 +90,13 @@ extern int check_logcat(const char *name);


/* logs a string */ /* logs a string */
#define logstring(cat, message) \ #define logstring(cat, message) \
{int p; if ((p = check_logcat(cat)) >= settings.log_level) \ {int p; if ((p = check_logcat(cat)) <= settings.log_level) \
{logstring0(p, cat, message);}} {logstring0(p, cat, message);}}
extern void logstring0(int priority, const char *cat, const char *message); extern void logstring0(int priority, const char *cat, const char *message);


/* logs a formated string */ /* logs a formated string */
#define printlogf(L, cat, ...) \ #define printlogf(L, cat, ...) \
{int p; if ((p = check_logcat(cat)) >= settings.log_level) \ {int p; if ((p = check_logcat(cat)) <= settings.log_level) \
{printlogf0(L, p, cat, __VA_ARGS__);}} {printlogf0(L, p, cat, __VA_ARGS__);}}
extern void extern void
printlogf0(lua_State *L, printlogf0(lua_State *L,
Expand Down

0 comments on commit c669051

Please sign in to comment.