Skip to content

Commit

Permalink
code: go on
Browse files Browse the repository at this point in the history
  • Loading branch information
HardySimpson committed Jul 21, 2013
1 parent 37f914d commit 83b9a97
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 258 deletions.
32 changes: 23 additions & 9 deletions src/category.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,43 @@
* Licensed under the LGPL v2.1, see the file COPYING in base directory.
*/

/*
* category is
* 1. the union of all fit rules for output
* 2. live only in one thread,
and has the rights to access all info of the thread,
category -> fit rules -> formats -> specs
|-> mdc |-> levels <-|
|-> event
* rules may depend other 2 things for output
* 1. zlog_env_rotater, access by lock
* 2. one record of rezlog_env_records,
as record is a funciton pointer stays in a static place,
just keep its adress is safe
*/

#ifndef __zlog_category_h
#define __zlog_category_h

typedef struct zlog_thread_s zlog_thread_t;

typedef struct zlog_category_s {
zc_sds name;
int *version;
zlog_event_t *event;
zlog_mdc_t *mdc;
unsigned char level_bitmap[32];
unsigned char level_bitmap_backup[32];
zc_arraylist_t *fit_rules;
zc_arraylist_t *fit_rules_backup;
} zlog_category_t;

zlog_category_t *zlog_category_new(const char *name, zc_arraylist_t * rules);
zlog_category_t *zlog_category_new(const char *name, zc_thread_t *a_thread);
void zlog_category_del(zlog_category_t * a_category);
void zlog_category_profile(zlog_category_t *a_category, int flag);

int zlog_category_update_rules(zlog_category_t * a_category, zc_arraylist_t * new_rules);
void zlog_category_commit_rules(zlog_category_t * a_category);
void zlog_category_rollback_rules(zlog_category_t * a_category);

int zlog_category_output(zlog_category_t * a_category, zlog_thread_t * a_thread);
int zlog_category_output(zlog_category_t * a_category);

#define zlog_category_needless_level(a_category, lv) \
!((a_category->level_bitmap[lv/8] >> (7 - lv % 8)) & 0x01)


#endif
8 changes: 4 additions & 4 deletions src/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
typedef struct zlog_conf_s {
zc_sds file;
long mtime;

int strict_init;
long auto_reload;
long expire_time;

zc_sds rotate_lock_file;
zc_sds default_deepness_str;
zc_sds default_format_str;

zlog_rotater_t *rotater;
zlog_deepness_t *default_deepness;
zlog_format_t *default_format;

Expand All @@ -29,10 +29,10 @@ 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);

zlog_conf_t *zlog_conf_dup(zlog_conf_t *a_conf);

#endif
1 change: 1 addition & 0 deletions src/rotater.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern zlog_rotate_t *zlog_env_rotater;

zlog_rotater_t *zlog_rotater_new(char *lock_file);
void zlog_rotater_del(zlog_rotater_t *a_rotater);
int zlog_rotater_reload(zlog_rotater_t *a_rotater, char *lock_file);

/*
* return
Expand Down
2 changes: 1 addition & 1 deletion src/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct zlog_rule_s {
//zlog_record_fn record_func;
};

zlog_rule_t *zlog_rule_new(char * line, zlog_conf_t * a_conf);
zlog_rule_t *zlog_rule_new(char * line, zlog_conf_t *a_conf);
void zlog_rule_del(zlog_rule_t * a_rule);
void zlog_rule_profile(zlog_rule_t * a_rule, int flag);
int zlog_rule_match_category(zlog_rule_t * a_rule, char *category);
Expand Down
23 changes: 15 additions & 8 deletions src/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@
#ifndef __zlog_thread_h
#define __zlog_thread_h

typedef struct {
int version;
zlog_conf_t *conf;
zlog_mdc_t *mdc;
zlog_event_t *event;
zc_hashtable_t *categories;
typedef zlog_category_s zlog_category_t;

typedef struct zlog_thread_s {
int version; /* compare to zlog_env_version, for update conf */
int idx; /* index of zlog_env_threads, for cleanup */
zlog_conf_t *conf; /* deep copy of zlog_env_conf */
zlog_mdc_t *mdc; /* tag map */
zlog_event_t *event; /* info of each log action */
zlog_category_t *default_category; /* has the same category name in dzlog api */
zc_hashtable_t *categories; /* all exist categories of this thread */
} zlog_thread_t;


zlog_thread_t *zlog_thread_new(int init_version, zlog_conf_t *a_conf);
zlog_thread_t *zlog_thread_new(zlog_conf_t *a_conf);
void zlog_thread_del(zlog_thread_t * a_thread);
void zlog_thread_profile(zlog_thread_t * a_thread, int flag);

int zlog_thread_reload(zlog_conf_t * a_conf);
#define zlog_thread_set_default_category(t, c) (t->default_category = (c))

zlog_category_t *zlog_thread_fetch_category(zlog_thread_t * a_thread, const char *cname, zc_hashtable_t *records);
int zlog_thread_update(zlog_thread_t *a_thread, zlog_conf_t * a_conf, zc_hashtable_t *records, int version);

#endif
11 changes: 9 additions & 2 deletions src/zc_arraylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,16 @@ int zc_arraylist_set(zc_arraylist_t * a_list, int idx, void *data)
return 0;
}

int zc_arraylist_add(zc_arraylist_t * a_list, void *data)
int zc_arraylist_add(zc_arraylist_t * a_list, void *data, int *idx)
{
return zc_arraylist_set(a_list, a_list->len, data);
int i;

for(i = 0; i < a_list->len; i++) {
if (a_list->array[i] == NULL) break;
}

if (idx) *idx = i;
return zc_arraylist_set(a_list, i, data);
}

/* assume idx < len */
Expand Down
2 changes: 1 addition & 1 deletion src/zc_arraylist.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void zc_arraylist_del(zc_arraylist_t * a_list);
zc_arraylist_t *zc_arraylist_dup(zc_arraylist_t * a_list);

int zc_arraylist_set(zc_arraylist_t * a_list, int i, void *data);
int zc_arraylist_add(zc_arraylist_t * a_list, void *data);
int zc_arraylist_add(zc_arraylist_t * a_list, void *data, int *idx);
int zc_arraylist_sortadd(zc_arraylist_t * a_list, void *data);

#define zc_arraylist_len(a_list) (a_list->len)
Expand Down
Loading

0 comments on commit 83b9a97

Please sign in to comment.