diff --git a/zlog/src/buf.c b/zlog/src/buf.c index b107c5a..62eb54c 100644 --- a/zlog/src/buf.c +++ b/zlog/src/buf.c @@ -241,8 +241,38 @@ int zlog_buf_vprintf(zlog_buf_t * a_buf, const char *format, va_list args) //*(a_buf->tail) = '\0'; return 0; } else if (nwrite < 0) { - zc_error("vsnprintf fail, errno[%d]", errno); - zc_error("nwrite[%d], size_left[%ld], format[%s]", nwrite, size_left, format); +#ifdef _MSC_VER + int rc; + do + { + rc = zlog_buf_resize(a_buf, a_buf->size_real * 2); + if (rc > 0) { + zc_error("conf limit to %ld, can't extend, so truncate", a_buf->size_max); + ap = args; + size_left = a_buf->end_plus_1 - a_buf->start; + vsnprintf(a_buf->tail, size_left, format, ap); + a_buf->tail += size_left - 1; + //*(a_buf->tail) = '\0'; + zlog_buf_truncate(a_buf); + return 1; + } else if (rc < 0) { + zc_error("zlog_buf_resize fail"); + return -1; + } else { + ap = args; + size_left = a_buf->end_plus_1 - a_buf->tail; + nwrite = vsnprintf(a_buf->tail, size_left, format, ap); + if (nwrite >0) { + break; + } + } + } while (rc == 0); + //zc_debug("nwrite[%d]>=size_left[%ld],format[%s],resize", nwrite, size_left, format); + + #else + zc_error("vsnprintf fail, errno[%d]", errno); + zc_error("nwrite[%d], size_left[%ld], format[%s]", nwrite, size_left, format); + #endif return -1; } else if (nwrite >= size_left) { int rc; diff --git a/zlog/src/conf.c b/zlog/src/conf.c index 7096149..0ff6f5c 100644 --- a/zlog/src/conf.c +++ b/zlog/src/conf.c @@ -50,12 +50,14 @@ #define ZLOG_CONF_DEFAULT_RELOAD_CONF_PERIOD 0 #define ZLOG_CONF_DEFAULT_FSYNC_PERIOD 0 #ifdef _MSC_VER -#define ZLOG_CONF_BACKUP_ROTATE_LOCK_FILE "d:/tmp/zlog.lock" +#define ZLOG_CONF_BACKUP_ROTATE_LOCK_FILE "zlog.lock" #else -#define ZLOG_CONF_BACKUP_ROTATE_LOCK_FILE "/tmp/zlog.lock" +#define ZLOG_CONF_BACKUP_ROTATE_LOCK_FILE "zlog.lock" #endif /*******************************************************************************/ +zlog_conf_t *zlog_env_conf; + void zlog_conf_profile(zlog_conf_t * a_conf, int flag) { int i; diff --git a/zlog/src/conf.h b/zlog/src/conf.h index 4ca755a..363c7cd 100644 --- a/zlog/src/conf.h +++ b/zlog/src/conf.h @@ -47,10 +47,12 @@ typedef struct zlog_conf_s { zc_arraylist_t *rules; } zlog_conf_t; -extern zlog_conf_t * zlog_env_conf; + zlog_conf_t *zlog_conf_new(const char *confpath); void zlog_conf_del(zlog_conf_t * a_conf); void zlog_conf_profile(zlog_conf_t * a_conf, int flag); +extern zlog_conf_t * zlog_env_conf; + #endif diff --git a/zlog/src/zc_profile.c b/zlog/src/zc_profile.c index 376e506..a6142a1 100644 --- a/zlog/src/zc_profile.c +++ b/zlog/src/zc_profile.c @@ -58,8 +58,8 @@ int zc_profile_inner(int flag, const char *file, const long line, const char *fm if (!init_flag) { init_flag = 1; - _putenv( "ZLOG_PROFILE_DEBUG=d:\\tmp\\debug.log" ); // C4996 - _putenv( "ZLOG_PROFILE_ERROR=d:\\tmp\\error.log" ); // C4996 + _putenv( "ZLOG_PROFILE_DEBUG=log/debug.log" ); // C4996 + _putenv( "ZLOG_PROFILE_ERROR=log/error.log" ); // C4996 debug_log = getenv("ZLOG_PROFILE_DEBUG"); error_log = getenv("ZLOG_PROFILE_ERROR"); printf("debug_log:%s\n",debug_log); diff --git a/zlog/src/zc_xplatform.h b/zlog/src/zc_xplatform.h index 77b1411..e62770b 100644 --- a/zlog/src/zc_xplatform.h +++ b/zlog/src/zc_xplatform.h @@ -35,8 +35,13 @@ #define MAXLEN_PATH 1024 #define MAXLEN_CFG_LINE (MAXLEN_PATH * 4) +#ifdef _MSC_VER +#define FILE_NEWLINE "\r\n" +#define FILE_NEWLINE_LEN 2 +#else #define FILE_NEWLINE "\n" #define FILE_NEWLINE_LEN 1 +#endif #include #ifndef _MSC_VER