2 * Copyright (C) 1995-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1999-11-30 13:47:12 adam
8 * Improved installation. Moved header files to include/yaz.
10 * Revision 1.2 1999/08/27 09:40:33 adam
11 * Renamed logf function to yaz_log. Removed VC++ project files.
13 * Revision 1.1 1999/06/08 10:10:16 adam
14 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
16 * Revision 1.1 1998/11/16 16:02:35 adam
17 * Added loggin utilies, log_rpn_query and log_scan_term. These used
18 * to be part of Zebra.
22 * Old logs from zlogs.c:
24 * Revision 1.9 1998/10/13 20:36:02 adam
25 * Changed "indent" format string in log messages.
27 * Revision 1.8 1998/04/02 14:35:29 adam
28 * First version of Zebra that works with compiled ASN.1.
30 * Revision 1.7 1998/01/29 13:40:11 adam
31 * Better logging for scan service.
33 * Revision 1.6 1997/09/29 09:06:41 adam
34 * Removed static var to make this module thread safe.
36 * Revision 1.5 1997/04/30 08:56:07 quinn
39 * Revision 1.4 1996/10/08 09:41:25 quinn
42 * Revision 1.3 1996/03/20 09:36:40 adam
43 * Function dict_lookup_grep got extra parameter, init_pos, which marks
44 * from which position in pattern approximate pattern matching should occur.
45 * Approximate pattern matching is used in relevance=re-2.
47 * Revision 1.2 1996/01/03 16:22:11 quinn
50 * Revision 1.1 1995/11/16 17:00:55 adam
51 * Better logging of rpn query.
58 #include <yaz/logrpn.h>
60 static void attrStr (int type, int value, enum oid_value ast, char *str)
77 sprintf (str, "relation=Less than");
80 sprintf (str, "relation=Less than or equal");
83 sprintf (str, "relation=Equal");
86 sprintf (str, "relation=Greater or equal");
89 sprintf (str, "relation=Greater than");
92 sprintf (str, "relation=Not equal");
95 sprintf (str, "relation=Phonetic");
98 sprintf (str, "relation=Stem");
101 sprintf (str, "relation=Relevance");
104 sprintf (str, "relation=AlwaysMatches");
107 sprintf (str, "relation");
114 sprintf (str, "position=First in field");
117 sprintf (str, "position=First in any subfield");
120 sprintf (str, "position=Any position in field");
123 sprintf (str, "position");
130 sprintf (str, "structure=Phrase");
133 sprintf (str, "structure=Word");
136 sprintf (str, "structure=Key");
139 sprintf (str, "structure=Year");
142 sprintf (str, "structure=Date");
145 sprintf (str, "structure=Word list");
148 sprintf (str, "structure=Date (un)");
151 sprintf (str, "structure=Name (norm)");
154 sprintf (str, "structure=Name (un)");
157 sprintf (str, "structure=Structure");
160 sprintf (str, "structure=urx");
163 sprintf (str, "structure=free-form-text");
166 sprintf (str, "structure=document-text");
169 sprintf (str, "structure=local-number");
172 sprintf (str, "structure=string");
175 sprintf (str, "structure=numeric string");
178 sprintf (str, "structure");
185 sprintf (str, "truncation=Right");
188 sprintf (str, "truncation=Left");
191 sprintf (str, "truncation=Left&right");
194 sprintf (str, "truncation=Do not truncate");
197 sprintf (str, "truncation=Process #");
200 sprintf (str, "truncation=re-1");
203 sprintf (str, "truncation=re-2");
206 sprintf (str, "truncation");
213 sprintf (str, "completeness=Incomplete subfield");
216 sprintf (str, "completeness=Complete subfield");
219 sprintf (str, "completeness=Complete field");
222 sprintf (str, "completeness");
231 sprintf (str + strlen(str), " (%d=%d)", type, value);
233 sprintf (str, "%d=%d", type, value);
237 * zlog_attributes: print attributes of term
239 static void zlog_attributes (Z_AttributesPlusTerm *t, int level,
245 int num_attributes = t->attributes->num_attributes;
247 int num_attributes = t->num_attributes;
250 for (of = 0; of < num_attributes; of++)
252 const char *attset_name = "";
253 Z_AttributeElement *element;
255 element = t->attributes->attributes[of];
257 element = t->attributeList[of];
259 if (element->attributeSet)
262 attrset = oid_getentbyoid (element->attributeSet);
263 attset_name = attrset->desc;
265 switch (element->which)
267 case Z_AttributeValue_numeric:
268 attrStr (*element->attributeType,
269 *element->value.numeric, ast, str);
270 yaz_log (LOG_LOG, "%*.0s%s %s", level, "", attset_name, str);
272 case Z_AttributeValue_complex:
273 yaz_log (LOG_LOG, "%*.0s%s attributeType=%d complex",
274 level, "", attset_name, *element->attributeType);
275 for (i = 0; i<element->value.complex->num_list; i++)
277 if (element->value.complex->list[i]->which ==
278 Z_StringOrNumeric_string)
279 yaz_log (LOG_LOG, "%*.0s string: '%s'", level, "",
280 element->value.complex->list[i]->u.string);
281 else if (element->value.complex->list[i]->which ==
282 Z_StringOrNumeric_numeric)
283 yaz_log (LOG_LOG, "%*.0s numeric: '%d'", level, "",
284 *element->value.complex->list[i]->u.numeric);
288 yaz_log (LOG_LOG, "%.*s%s attribute unknown",
289 level, "", attset_name);
294 static void zlog_structure (Z_RPNStructure *zs, int level, enum oid_value ast)
296 if (zs->which == Z_RPNStructure_complex)
298 switch (zs->u.complex->roperator->which)
301 yaz_log (LOG_LOG, "%*.0s and", level, "");
304 yaz_log (LOG_LOG, "%*.0s or", level, "");
306 case Z_Operator_and_not:
307 yaz_log (LOG_LOG, "%*.0s and-not", level, "");
310 yaz_log (LOG_LOG, "%*.0s unknown complex", level, "");
313 zlog_structure (zs->u.complex->s1, level+2, ast);
314 zlog_structure (zs->u.complex->s2, level+2, ast);
316 else if (zs->which == Z_RPNStructure_simple)
318 if (zs->u.simple->which == Z_Operand_APT)
320 Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
322 if (zapt->term->which == Z_Term_general)
324 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
325 zapt->term->u.general->len,
326 zapt->term->u.general->buf);
330 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
332 zlog_attributes (zapt, level+2, ast);
334 else if (zs->u.simple->which == Z_Operand_resultSetId)
336 yaz_log (LOG_LOG, "%*.0s set '%s'", level, "",
337 zs->u.simple->u.resultSetId);
340 yaz_log (LOG_LOG, "%*.0s unknown simple structure", level, "");
343 yaz_log (LOG_LOG, "%*.0s unknown structure", level, "");
346 void log_rpn_query (Z_RPNQuery *rpn)
351 attrset = oid_getentbyoid (rpn->attributeSetId);
354 ast = attrset->value;
355 yaz_log (LOG_LOG, "RPN query. Type: %s", attrset->desc);
360 yaz_log (LOG_LOG, "RPN query. Unknown type");
362 zlog_structure (rpn->RPNStructure, 0, ast);
365 void log_scan_term (Z_AttributesPlusTerm *zapt, oid_value ast)
368 if (zapt->term->which == Z_Term_general)
370 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
371 zapt->term->u.general->len, zapt->term->u.general->buf);
374 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
375 zlog_attributes (zapt, level+2, ast);