diff options
author | Edward Rudd <urkle@outoforder.cc> | 2008-10-25 04:25:56 (GMT) |
---|---|---|
committer | Edward Rudd <urkle@outoforder.cc> | 2008-10-25 04:25:56 (GMT) |
commit | caae8dcfed1462cb19c82f99087e6fe2ba3d407c (patch) | |
tree | c575ead091166c6674111b4d214e87487f38e991 /utility/shell.c | |
parent | 19bbdd68a491721dd4aeff7cacea51148ce3a9b9 (diff) |
implemented logging
added better error messages for DB connections
fix several segfaults
Diffstat (limited to 'utility/shell.c')
-rw-r--r-- | utility/shell.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/utility/shell.c b/utility/shell.c index b289bce..e521916 100644 --- a/utility/shell.c +++ b/utility/shell.c | |||
@@ -17,9 +17,10 @@ const apr_getopt_option_t _opt_config[] = { | |||
17 | {"transaction", 't', 1, "Use a Transaction (yes,no)"}, | 17 | {"transaction", 't', 1, "Use a Transaction (yes,no)"}, |
18 | {"logformat", 'r', 1, "Use this logformat to parse files"}, | 18 | {"logformat", 'r', 1, "Use this logformat to parse files"}, |
19 | {"file", 'f', 1, "Parse this single log file (input dir is NOT scanned)"}, | 19 | {"file", 'f', 1, "Parse this single log file (input dir is NOT scanned)"}, |
20 | {"inputdir", 'd', 1, "Input Directory to look for log files"}, | 20 | {"inputdir", 'i', 1, "Input Directory to look for log files"}, |
21 | {"config", 'c', 1, "Configuration file to use (default mod_log_sql.conf)"}, | 21 | {"config", 'c', 1, "Configuration file to use (default mod_log_sql.conf)"}, |
22 | {"dryrun", 'n', 0, "Perform a dry run (do not actually alter the databse)"}, | 22 | {"dryrun", 'n', 0, "Perform a dry run (do not actually alter the databse)"}, |
23 | {"dump", 'd', 0, "Dump the configuration after parsing and quit"}, | ||
23 | {"loglevel", 'l', 1, "Log Level (deubg, warn, error)"}, | 24 | {"loglevel", 'l', 1, "Log Level (deubg, warn, error)"}, |
24 | {"summary", 's', 1, "Summary (yes,no)"}, | 25 | {"summary", 's', 1, "Summary (yes,no)"}, |
25 | {"help", 'h', 0, "Show Help"}, | 26 | {"help", 'h', 0, "Show Help"}, |
@@ -62,7 +63,7 @@ int main(int argc, const char *const argv[]) | |||
62 | const char *opt_arg; | 63 | const char *opt_arg; |
63 | apr_status_t rv; | 64 | apr_status_t rv; |
64 | apr_table_t *args; | 65 | apr_table_t *args; |
65 | config_t *base; | 66 | config_t *cfg; |
66 | 67 | ||
67 | apr_app_initialize(&argc, &argv, NULL); | 68 | apr_app_initialize(&argc, &argv, NULL); |
68 | atexit(apr_terminate); | 69 | atexit(apr_terminate); |
@@ -84,7 +85,7 @@ int main(int argc, const char *const argv[]) | |||
84 | apr_table_setn(args,"config",opt_arg); | 85 | apr_table_setn(args,"config",opt_arg); |
85 | break; | 86 | break; |
86 | case 'd': | 87 | case 'd': |
87 | apr_table_setn(args,"inputdirectory",opt_arg); | 88 | apr_table_setn(args,"dump","yes"); |
88 | break; | 89 | break; |
89 | case 'f': | 90 | case 'f': |
90 | apr_table_setn(args,"inputfile",opt_arg); | 91 | apr_table_setn(args,"inputfile",opt_arg); |
@@ -93,6 +94,9 @@ int main(int argc, const char *const argv[]) | |||
93 | show_help(argv[0], _opt_config, stdout); | 94 | show_help(argv[0], _opt_config, stdout); |
94 | exit(1); | 95 | exit(1); |
95 | break; | 96 | break; |
97 | case 'i': | ||
98 | apr_table_setn(args,"inputdirectory",opt_arg); | ||
99 | break; | ||
96 | case 'l': | 100 | case 'l': |
97 | apr_table_setn(args,"loglevel",opt_arg); | 101 | apr_table_setn(args,"loglevel",opt_arg); |
98 | break; | 102 | break; |
@@ -128,45 +132,49 @@ int main(int argc, const char *const argv[]) | |||
128 | parser_init(pool); | 132 | parser_init(pool); |
129 | config_init(pool); | 133 | config_init(pool); |
130 | database_init(pool); | 134 | database_init(pool); |
131 | logging_init(pool); | ||
132 | // Process configuration file | 135 | // Process configuration file |
133 | base = config_create(pool); | 136 | cfg = config_create(pool); |
134 | rv = config_read(base, apr_table_get(args,"Config"), args); | 137 | rv = config_read(cfg, apr_table_get(args,"Config"), args); |
135 | apr_pool_destroy(ptemp); | 138 | apr_pool_destroy(ptemp); |
136 | 139 | ||
140 | // Initialize Log system AFTER we parse the configuration | ||
141 | logging_init(cfg); | ||
142 | |||
137 | if (APR_STATUS_IS_ENOENT(rv)) { | 143 | if (APR_STATUS_IS_ENOENT(rv)) { |
138 | fprintf(stderr,"Could not load configuration file: %s\n",apr_table_get(args,"config")); | 144 | logging_log(cfg,LOGLEVEL_NOISE,"Could not load configuration file: %s",apr_table_get(args,"config")); |
139 | } else if (rv) { | 145 | } else if (rv) { |
140 | exit(1); | 146 | exit(1); |
141 | } | 147 | } |
142 | config_dump(base); | 148 | if (cfg->dump) { |
149 | config_dump(cfg); | ||
150 | exit(0); | ||
151 | } | ||
143 | 152 | ||
144 | if (config_check(base)) { | 153 | if (config_check(cfg)) { |
145 | printf("Please correct the configuration\n"); | 154 | logging_log(cfg,LOGLEVEL_NOISE, "Please correct the configuration"); |
146 | exit(1); | 155 | exit(1); |
147 | } | 156 | } |
148 | 157 | ||
149 | // Find files and parse | 158 | // Find files and parse |
150 | parser_find_logs(base); | 159 | parser_find_logs(cfg); |
151 | if (!base->dryrun) { | 160 | if (!cfg->dryrun) { |
152 | if ((rv = database_connect(base))) { | 161 | if ((rv = database_connect(cfg))) { |
153 | printf("Error Connecting to Database: %d\n",rv); | 162 | logging_log(cfg,LOGLEVEL_NOISE, "Error Connecting to Database"); |
154 | exit(1); | 163 | exit(1); |
155 | } | 164 | } |
156 | } | 165 | } |
157 | if (!apr_is_empty_array(base->input_files)) { | 166 | if (!apr_is_empty_array(cfg->input_files)) { |
158 | char **filelist; | 167 | char **filelist; |
159 | int f, l; | 168 | int f, l; |
160 | filelist = (char **)base->input_files->elts; | 169 | filelist = (char **)cfg->input_files->elts; |
161 | for (f=0, l=base->input_files->nelts; f < l; f++) { | 170 | for (f=0, l=cfg->input_files->nelts; f < l; f++) { |
162 | printf("Scanning %s\n",filelist[f]); | 171 | parse_logfile(cfg, filelist[f]); |
163 | parse_logfile(base, filelist[f]); | ||
164 | } | 172 | } |
165 | } else { | 173 | } else { |
166 | printf("No input files\n"); | 174 | logging_log(cfg,LOGLEVEL_NOISE,"No log files found to parse"); |
167 | } | 175 | } |
168 | if (!base->dryrun) { | 176 | if (!cfg->dryrun) { |
169 | database_disconnect(base); | 177 | database_disconnect(cfg); |
170 | } | 178 | } |
171 | /** @todo summary goes here */ | 179 | /** @todo summary goes here */ |
172 | return 0; | 180 | return 0; |