示例#1
0
MARPAWRAPPER_EXPORT void genericLogger_log(const genericLogger_t *genericLoggerp, genericLoggerLevel_t leveli, const char *fmts, ...) {
  va_list                ap;
#ifdef VA_COPY
  va_list                ap2;
#endif
  char                  *msgs;
  static const char     *emptyMessages = "Empty message";
  genericLoggerCallback_t  logCallbackp;
  void                  *userDatavp;
  genericLoggerLevel_t     genericLoggerDefaultLogLeveli;

  if (genericLoggerp != NULL) {
    if (genericLoggerp->genericLoggerOption.logCallbackp != NULL) {
      logCallbackp = genericLoggerp->genericLoggerOption.logCallbackp;
    } else {
      logCallbackp = &_genericLogger_defaultCallback;
    }
    userDatavp = genericLoggerp->genericLoggerOption.userDatavp;
    genericLoggerDefaultLogLeveli = genericLoggerp->genericLoggerOption.leveli;
  } else {
    userDatavp = NULL;
    logCallbackp = &_genericLogger_defaultCallback;
    genericLoggerDefaultLogLeveli = GENERICLOGGER_LOGLEVEL_WARNING;
  }

  if (leveli >= genericLoggerDefaultLogLeveli) {

    va_start(ap, fmts);
#ifdef VA_COPY
    VA_COPY(ap2, ap);
    msgs = (fmts != NULL) ? messageBuilder_ap(fmts, ap2) : (char *) emptyMessages;
    va_end(ap2);
#else
    msgs = (fmts != NULL) ? messageBuilder_ap(fmts, ap) : (char *) emptyMessages;
#endif
    va_end(ap);

    if (msgs != messageBuilder_internalErrors()) {
      logCallbackp(userDatavp, leveli, msgs);
    } else {
      logCallbackp(userDatavp, GENERICLOGGER_LOGLEVEL_ERROR, msgs);
    }

    if (msgs != emptyMessages && msgs != messageBuilder_internalErrors()) {
      /* No need to assign to NULL, this is a local variable and we will return just after */
      free(msgs);
    }
  }

}
示例#2
0
文件: log.c 项目: jddurand/marpaXml
void marpaXml_log(marpaXmlLog_t *marpaXmlLogp, marpaXmlLogLevel_t marpaXmlLogLeveli, const char *fmts, ...) {
  va_list                ap;
#ifdef VA_COPY
  va_list                ap2;
#endif
  char                  *msgs;
  static const char     *emptyMessages = "Empty message";
  marpaXmlLogCallback_t  logCallbackp;
  void                  *userDatavp;
  marpaXmlLogLevel_t     marpaXmlDefaultLogLeveli;

  if (marpaXmlLogp != NULL) {
    if (marpaXmlLogp->logCallbackp != NULL) {
      logCallbackp = marpaXmlLogp->logCallbackp;
    } else {
      logCallbackp = &_marpaXmlLog_defaultCallback;
    }
    userDatavp = marpaXmlLogp->userDatavp;
    marpaXmlDefaultLogLeveli = marpaXmlLogp->marpaXmlLogLeveli;
  } else {
    userDatavp = NULL;
    logCallbackp = &_marpaXmlLog_defaultCallback;
    marpaXmlDefaultLogLeveli = MARPAXML_LOGLEVEL_WARNING;
  }

  if (marpaXmlLogLeveli >= marpaXmlDefaultLogLeveli) {

    va_start(ap, fmts);
#ifdef VA_COPY
    VA_COPY(ap2, ap);
    msgs = (fmts != NULL) ? messageBuilder_ap(fmts, ap2) : (char *) emptyMessages;
    va_end(ap2);
#else
    msgs = (fmts != NULL) ? messageBuilder_ap(fmts, ap) : (char *) emptyMessages;
#endif
    va_end(ap);

    if (msgs != messageBuilder_internalErrors()) {
      logCallbackp(userDatavp, marpaXmlLogLeveli, msgs);
    } else {
      logCallbackp(userDatavp, MARPAXML_LOGLEVEL_ERROR, msgs);
    }

    if (msgs != emptyMessages && msgs != messageBuilder_internalErrors()) {
      /* No need to assign to NULL, this is a local variable and we will return just after */
      free(msgs);
    }
  }

}