Changeset 6617


Ignore:
Timestamp:
Nov 11, 2016 3:50:35 AM (8 years ago)
Author:
ldelgass
Message:

More logging fixes

Location:
pymolproxy/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pymolproxy/trunk/Makefile.in

    r6605 r6617  
     1WANT_DEBUG      = #yes
    12
    23TARGETS =       pymolproxy
     
    89                -DSVN_VERSION=\"$(SVN_VERSION)\" \
    910                -DSTATSDIR=\"$(STATSDIR)\" \
    10                 -DLOGDIR=\"$(LOGDIR)\" 
     11                -DLOGDIR=\"$(LOGDIR)\"
    1112EXTRA_CFLAGS =  -Wall
    1213INCLUDES =      $(TCL_INC_SPEC) -I$(srcdir)
     
    3132STATSDIR        = @STATSDIR@
    3233LOGDIR          = @LOGDIR@
     34
     35ifdef WANT_DEBUG
     36DEFINES += -DWANT_DEBUG
     37endif
    3338
    3439.PHONY: all install clean distclean
  • pymolproxy/trunk/pymolproxy.c

    r6614 r6617  
    9999#define TRUE  1
    100100
    101 static int debug = FALSE;
    102 static FILE *frecord;
     101static FILE *frecord = NULL;
     102static FILE *flog = NULL;
    103103static int recording = FALSE;
    104104static int pymolIsAlive = TRUE;
    105105static int statsFile = -1;
    106106
    107 #define WANT_DEBUG  0
    108 #define READ_DEBUG  0
    109 #define WRITE_DEBUG 0
    110 #define EXEC_DEBUG  0
     107#define READ_DEBUG  1
     108#define WRITE_DEBUG 1
     109#define EXEC_DEBUG  1
    111110#define LOG_PYMOL_STDERR 0
    112111
     
    213212} PymolProxy;
    214213
    215 #if WANT_DEBUG
    216 #define DEBUG(...) if (debug) PrintToLog(__VA_ARGS__)
     214#ifdef WANT_DEBUG
     215#define DEBUG(...) PrintToLog(__VA_ARGS__)
    217216#else
    218217#define DEBUG(...)
     
    224223#define INFO(...)  SysLog(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
    225224
     225#if 0
    226226static const char *syslogLevels[] = {
    227227    "emergency", /* System is unusable */
     
    234234    "debug",     /* Debug-level messages */
    235235};
    236 
    237 #if WANT_DEBUG
     236#endif
     237
     238#ifdef WANT_DEBUG
    238239static void
    239240PrintToLog(const char *format, ...)
     
    241242    va_list args;
    242243
     244    if (flog == NULL) return;
     245
    243246    va_start(args, format);
    244     fprintf(stderr, "pymolproxy: ");
    245     vfprintf(stderr, format, args);
     247    fprintf(flog, "pymolproxy: ");
     248    vfprintf(flog, format, args);
    246249    va_end(args);
    247     fprintf(stderr, "\n");
    248     fflush(stderr);
     250    fprintf(flog, "\n");
     251    fflush(flog);
    249252}
    250253#endif
     
    266269        s++;
    267270    }
    268     length = snprintf(message, MSG_LEN, "pymolproxy (%d) %s: %s:%d ",
    269         getpid(), syslogLevels[priority],  s, lineNum);
     271    length = snprintf(message, MSG_LEN, "%s:%d: ", s, lineNum);
    270272    length += vsnprintf(message + length, MSG_LEN - length, fmt, lst);
    271273    message[MSG_LEN] = '\0';
    272274    va_end(lst);
    273275
    274     if (debug) {
     276    if (priority == LOG_DEBUG) {
    275277        DEBUG("%s", message);
    276278    } else {
     
    283285{
    284286    va_list args;
     287
     288    if (frecord == NULL) return;
    285289
    286290    va_start(args, format);
     
    22802284            status = GetLine(&p->client, &numBytes, &line);
    22812285            if (status != BUFFER_OK) {
    2282                 ERROR("can't read client stdout (numBytes=%d, status=%d): %s",
    2283                       numBytes, status, strerror(errno));
     2286                if (status == BUFFER_EOF) {
     2287                    DEBUG("Exiting server on EOF from client");
     2288                } else {
     2289                    ERROR("Exiting server, failed to read from client (numBytes=%d, status=%d): %s",
     2290                          numBytes, status, strerror(errno));
     2291                }
    22842292                goto done;
    22852293            }
     
    24392447        ERROR("Short write on version string", strerror(errno));
    24402448    }
     2449
     2450    flog = stderr;
     2451    openlog("pymolproxy", LOG_CONS | LOG_PERROR | LOG_PID, LOG_USER);
    24412452    DEBUG("Starting pymolproxy");
    24422453
Note: See TracChangeset for help on using the changeset viewer.