Skip to content

Commit

Permalink
Merge commit 'v1.0.5'
Browse files Browse the repository at this point in the history
Conflicts:
	libzlog/rule.c
  • Loading branch information
HardySimpson committed Jun 15, 2012
2 parents cd1c002 + 29b0252 commit 724c04d
Show file tree
Hide file tree
Showing 14 changed files with 395 additions and 284 deletions.
7 changes: 0 additions & 7 deletions libzlog/buf.c
Expand Up @@ -163,13 +163,6 @@ zlog_buf_t *zlog_buf_new(size_t buf_size_min, size_t buf_size_max,
}
}

/*******************************************************************************/
void zlog_buf_restart(zlog_buf_t * a_buf)
{
a_buf->end = a_buf->start;
return;
}

/*******************************************************************************/
int zlog_buf_printf(zlog_buf_t * a_buf, const char *format, ...)
{
Expand Down
5 changes: 4 additions & 1 deletion libzlog/buf.h
Expand Up @@ -40,7 +40,10 @@ zlog_buf_t *zlog_buf_new(size_t buf_size_min, size_t buf_size_max,
void zlog_buf_del(zlog_buf_t * a_buf);
void zlog_buf_profile(zlog_buf_t * a_buf, int flag);

void zlog_buf_restart(zlog_buf_t * a_buf);
#define zlog_buf_restart(a_buf) do { \
a_buf->end = a_buf->start; \
} while(0);

int zlog_buf_printf(zlog_buf_t * a_buf, const char *format, ...);
int zlog_buf_vprintf(zlog_buf_t * a_buf, const char *format, va_list args);
int zlog_buf_append(zlog_buf_t * a_buf, const char *str, size_t str_len);
Expand Down
74 changes: 23 additions & 51 deletions libzlog/conf.c
Expand Up @@ -38,33 +38,12 @@
#define ZLOG_CONF_DEFAULT_RULE "*.* >stdout"
#define ZLOG_CONF_DEFAULT_BUF_SIZE_MIN 1024
#define ZLOG_CONF_DEFAULT_BUF_SIZE_MAX (2 * 1024 * 1024)
#define ZLOG_CONF_DEFAULT_ROTATE_LOCK_FILE "/tmp/zlog.lock"
#define ZLOG_CONF_DEFAULT_FILE_PERMS 0600
#define ZLOG_CONF_DEFAULT_RELOAD_CONF_PERIOD 0
#define ZLOG_CONF_DEFAULT_FSYNC_PERIOD 0
#define ZLOG_CONF_BACKUP_ROTATE_LOCK_FILE "/tmp/zlog.lock"
/*******************************************************************************/

struct zlog_conf_s {
char file[MAXLEN_PATH + 1];
char mtime[20 + 1];

int strict_init;
size_t buf_size_min;
size_t buf_size_max;

char rotate_lock_file[MAXLEN_CFG_LINE + 1];
zlog_rotater_t *rotater;

zc_arraylist_t *levels;

char default_format_line[MAXLEN_CFG_LINE + 1];
zlog_format_t *default_format;

unsigned int file_perms;

zc_arraylist_t *formats;

zc_arraylist_t *rules;
};

void zlog_conf_profile(zlog_conf_t * a_conf, int flag)
{
int i;
Expand All @@ -83,6 +62,8 @@ void zlog_conf_profile(zlog_conf_t * a_conf, int flag)
zlog_format_profile(a_conf->default_format, flag);
}
zc_profile(flag, "---file perms[0%o]---", a_conf->file_perms);
zc_profile(flag, "---reload conf period[%ld]---", a_conf->reload_conf_period);
zc_profile(flag, "---fsync period[%ld]---", a_conf->fsync_period);

zc_profile(flag, "---rotate lock file[%s]---", a_conf->rotate_lock_file);
if (a_conf->rotater) zlog_rotater_profile(a_conf->rotater, flag);
Expand Down Expand Up @@ -155,18 +136,23 @@ zlog_conf_t *zlog_conf_new(char *conf_file)
a_conf->strict_init = 1;
a_conf->buf_size_min = ZLOG_CONF_DEFAULT_BUF_SIZE_MIN;
a_conf->buf_size_max = ZLOG_CONF_DEFAULT_BUF_SIZE_MAX;
strcpy(a_conf->rotate_lock_file, ZLOG_CONF_DEFAULT_ROTATE_LOCK_FILE);
if (has_conf_file) {
strcpy(a_conf->rotate_lock_file, a_conf->file);
} else {
strcpy(a_conf->rotate_lock_file, ZLOG_CONF_BACKUP_ROTATE_LOCK_FILE);
}
strcpy(a_conf->default_format_line, ZLOG_CONF_DEFAULT_FORMAT);
a_conf->file_perms = ZLOG_CONF_DEFAULT_FILE_PERMS;
a_conf->reload_conf_period = ZLOG_CONF_DEFAULT_RELOAD_CONF_PERIOD;
a_conf->fsync_period = ZLOG_CONF_DEFAULT_FSYNC_PERIOD;
/* set default configuration end */

a_conf->levels = zlog_level_list_new();
if (!a_conf->levels) {
zc_error("zlog_level_list_new fail");
rc = -1;
goto zlog_conf_new_exit;
}

}
a_conf->formats = zc_arraylist_new((zc_arraylist_del_fn) zlog_format_del);
if (!a_conf->formats) {
zc_error("zc_arraylist_new fail");
Expand Down Expand Up @@ -228,7 +214,8 @@ static int zlog_conf_build_without_file(zlog_conf_t * a_conf)
a_conf->levels,
a_conf->default_format,
a_conf->formats,
a_conf->file_perms);
a_conf->file_perms,
a_conf->fsync_period);
if (!default_rule) {
zc_error("zlog_rule_new fail");
return -1;
Expand Down Expand Up @@ -447,6 +434,11 @@ static int zlog_conf_parse_line(zlog_conf_t * a_conf, char *line, int *section)
} else if (STRCMP(word_1, ==, "default") && STRCMP(word_2, ==, "format")) {
/* so the input now is [format = "xxyy"], fit format's style */
strcpy(a_conf->default_format_line, line + nread);
} else if (STRCMP(word_1, ==, "reload") &&
STRCMP(word_2, ==, "conf") && STRCMP(word_3, ==, "period")) {
a_conf->reload_conf_period = zc_parse_byte_size(value);
} else if (STRCMP(word_1, ==, "fsync") && STRCMP(word_2, ==, "period")) {
a_conf->fsync_period = zc_parse_byte_size(value);
} else {
zc_error("name[%s] is not any one of global options", name);
if (a_conf->strict_init) return -1;
Expand Down Expand Up @@ -479,7 +471,9 @@ static int zlog_conf_parse_line(zlog_conf_t * a_conf, char *line, int *section)
a_conf->levels,
a_conf->default_format,
a_conf->formats,
a_conf->file_perms);
a_conf->file_perms,
a_conf->fsync_period);

if (!a_rule) {
zc_error("zlog_rule_new fail [%s]", line);
if (a_conf->strict_init) return -1;
Expand All @@ -501,25 +495,3 @@ static int zlog_conf_parse_line(zlog_conf_t * a_conf, char *line, int *section)
return 0;
}
/*******************************************************************************/
zc_arraylist_t *zlog_conf_get_rules(zlog_conf_t *a_conf)
{
zc_assert(a_conf, NULL);
return a_conf->rules;
}

void zlog_conf_get_buf_size(zlog_conf_t *a_conf,
size_t * buf_size_min, size_t * buf_size_max)
{
zc_assert(a_conf,);
zc_assert(buf_size_min,);
zc_assert(buf_size_max,);

*buf_size_min = a_conf->buf_size_min;
*buf_size_max = a_conf->buf_size_max;
}

char *zlog_conf_get_file(zlog_conf_t *a_conf)
{
zc_assert(a_conf, NULL);
return a_conf->file;
}
29 changes: 23 additions & 6 deletions libzlog/conf.h
Expand Up @@ -22,16 +22,33 @@

#include "zc_defs.h"
#include "format.h"
#include "rotater.h"

typedef struct zlog_conf_s zlog_conf_t;
typedef struct zlog_conf_s {
char file[MAXLEN_PATH + 1];
char mtime[20 + 1];

int strict_init;
size_t buf_size_min;
size_t buf_size_max;

char rotate_lock_file[MAXLEN_CFG_LINE + 1];
zlog_rotater_t *rotater;

char default_format_line[MAXLEN_CFG_LINE + 1];
zlog_format_t *default_format;

unsigned int file_perms;
size_t fsync_period;
size_t reload_conf_period;

zc_arraylist_t *levels;
zc_arraylist_t *formats;
zc_arraylist_t *rules;
} zlog_conf_t;

zlog_conf_t *zlog_conf_new(char *conf_file);
void zlog_conf_del(zlog_conf_t * a_conf);
void zlog_conf_profile(zlog_conf_t * a_conf, int flag);

zc_arraylist_t *zlog_conf_get_rules(zlog_conf_t *a_conf);
void zlog_conf_get_buf_size(zlog_conf_t *a_conf,
size_t * buf_size_min, size_t * buf_size_max);
char *zlog_conf_get_file(zlog_conf_t *a_conf);

#endif
1 change: 1 addition & 0 deletions libzlog/event.h
Expand Up @@ -51,6 +51,7 @@ typedef struct {
zlog_event_cmd generate_cmd;

struct timeval time_stamp;
time_t last_sec;
struct tm local_time;
char us[6 + 1];
char time_fmt_msus[MAXLEN_CFG_LINE + 1];
Expand Down
11 changes: 5 additions & 6 deletions libzlog/rotater.c
Expand Up @@ -450,13 +450,11 @@ int zlog_rotater_rotate(zlog_rotater_t *a_rotater,

rc = stat(file_path, &info);
if (rc) {
zc_error("stat [%s] fail, errno[%d]", file_path, errno);
return -1;
zc_warn("stat [%s] fail, errno[%d], maybe in rotating", file_path, errno);
return 0;
} else {
if (info.st_size + msg_len < file_max_size) {
/* file not so big, return */
return 0;
}
/* file not so big, return */
if (info.st_size + msg_len < file_max_size) return 0;
}

rd = zlog_rotater_trylock(a_rotater);
Expand Down Expand Up @@ -487,6 +485,7 @@ int zlog_rotater_rotate(zlog_rotater_t *a_rotater,
rc = -1;
goto zlog_rotater_rotate_exit;
} else if (rc == 0) {
rc = 1;
zc_debug("zlog_rotater_file_ls_mv success");
}

Expand Down
7 changes: 7 additions & 0 deletions libzlog/rotater.h
Expand Up @@ -26,6 +26,13 @@ typedef struct zlog_rotater_s zlog_rotater_t;

zlog_rotater_t *zlog_rotater_new(char *lock_file);
void zlog_rotater_del(zlog_rotater_t *a_rot);

/*
* return
* -1 fail
* 0 no rotate
* 1 rotate and success
*/
int zlog_rotater_rotate(zlog_rotater_t *a_rot,
char *file_path, long file_max_size, int file_max_count,
size_t msg_len);
Expand Down

0 comments on commit 724c04d

Please sign in to comment.