14
15
16:- module(error_logger,
17 [
18 clear_messages/0,
19 clear_messages/1, 20 clear_error_messages/0,
21 clear_error_messages_sentence/1, 22 clear_warning_messages/0,
23 get_messages/1, 24 get_messages_in_xml/1, 25 get_error_messages/1, 26 get_warning_messages/1, 27 get_messages_with_type/2, 28 get_error_messages_with_type/2, 29 get_warning_messages_with_type/2, 30 add_error_messagelist/4, 31 add_error_message/4, 32 add_error_message_once/4, 33 add_warning_message/4, 34 add_warning_message_once/4, 35 add_messages/1, 36 is_error_message/4, 37 messages_xmlmessages/2 38 ]).
53clear_messages :-
54 setval(message, []).
63clear_messages(Type) :-
64 getval(message, Messages),
65 myexclude(message(_, Type, _, _, _), Messages, RemainingMessages),
66 setval(message, RemainingMessages),
67 !.
68
69clear_messages(_).
76clear_error_messages :-
77 getval(message, Messages),
78 myexclude(message(error, _, _, _, _), Messages, RemainingMessages),
79 setval(message, RemainingMessages),
80 !.
81
82clear_error_messages.
89clear_warning_messages :-
90 getval(message, Messages),
91 myexclude(message(warning, _, _, _, _), Messages, RemainingMessages),
92 setval(message, RemainingMessages),
93 !.
94
95clear_warning_messages.
104clear_error_messages_sentence(Sentence) :-
105 getval(message, Messages),
106 myexclude(message(error, _, Sentence-_, _, _), Messages, RemainingMessages),
107 setval(message, RemainingMessages),
108 !.
109
110clear_error_messages_sentence(_).
116get_messages(Messages) :-
117 getval(message, MessagesR),
118 reverse(MessagesR, Messages).
125get_messages_in_xml(XmlMessages) :-
126 get_messages(Messages),
127 messages_xmlmessages(Messages, XmlMessages).
137messages_xmlmessages([], []).
138
139messages_xmlmessages(
140 [message(Importance, Type, SentenceId-TokenId, Subject, Description) | Messages],
141 [element(message, [importance=Importance, type=Type, sentence=SentenceId, token=TokenId, value=Subject, repair=Description], [])
142 | XmlMessages]
143 ) :-
144 messages_xmlmessages(Messages, XmlMessages).
152get_error_messages(ErrorMessages) :-
153 get_messages(Messages),
154 findall(message(error, T, P, S, D), member(message(error, T, P, S, D), Messages), ErrorMessages).
161get_warning_messages(WarningMessages) :-
162 get_messages(Messages),
163 findall(message(warning, T, P, S, D), member(message(warning, T, P, S, D), Messages), WarningMessages).
171get_messages_with_type(Type, AllMessages) :-
172 get_messages(Messages),
173 findall(message(Importance, Type, P, S, D), member(message(Importance, Type, P, S, D), Messages), AllMessages).
181get_error_messages_with_type(Type, ErrorMessages) :-
182 get_messages(Messages),
183 findall(message(error, Type, P, S, D), member(message(error, Type, P, S, D), Messages), ErrorMessages).
191get_warning_messages_with_type(Type, WarningMessages) :-
192 get_messages(Messages),
193 findall(message(warning, Type, P, S, D), member(message(warning, Type, P, S, D), Messages), WarningMessages).
203add_error_messagelist(_Type, _Position, _Subject, []).
204
205add_error_messagelist(Type, Position, Subject, [H | T]) :-
206 add_error_message(Type, Position, Subject, H),
207 add_error_messagelist(Type, Position, Subject, T).
217add_error_message(Type, Position, Subject, Description) :-
218 assert_message(error, Type, Position, Subject, Description).
224add_error_message_once(Type, Position, Subject, Description) :-
225 assert_message_once(error, Type, Position, Subject, Description).
231add_warning_message(Type, Position, Subject, Description) :-
232 assert_message(warning, Type, Position, Subject, Description).
238add_warning_message_once(Type, Position, Subject, Description) :-
239 assert_message_once(warning, Type, Position, Subject, Description).
245add_messages(MessageList) :-
246 getval(message, OldMessages),
247 reverse(MessageList, MessageListR),
248 append(MessageListR, OldMessages, NewMessages),
249 setval(message, NewMessages).
260assert_message(Importance, Type, SentenceID-TokenID, Subject, Description) :-
261 ground(message(Importance, Type, SentenceID-TokenID, Subject, Description)),
262 !,
263 264 265 getval(message, Messages),
266 setval(message, [message(Importance, Type, SentenceID-TokenID, Subject, Description) | Messages]).
267
268assert_message(Importance, Type, SentenceID-TokenID, Subject, Description) :-
269 format(user_error, 'Malformed message: ~q\n', [message(Importance, Type, SentenceID-TokenID, Subject, Description)]),
270 !.
271
272assert_message(Importance, Type, SentenceID, Subject, Description) :-
273 assert_message(Importance, Type, SentenceID-'', Subject, Description).
279assert_message_once(Importance, Type, SentenceID-TokenID, Subject, Description) :-
280 getval(message, Messages),
281 member(message(Importance, Type, SentenceID-TokenID, Subject, Description), Messages),
282 283 !.
284
285assert_message_once(Importance, Type, SentenceID-TokenID, Subject, Description) :-
286 !,
287 assert_message(Importance, Type, SentenceID-TokenID, Subject, Description).
288
289assert_message_once(Importance, Type, SentenceID, Subject, Description) :-
290 assert_message_once(Importance, Type, SentenceID-'', Subject, Description).
297is_error_message(Type, Position, Subject, Description) :-
298 getval(message, Messages),
299 member(message(error, Type, Position, Subject, Description), Messages),
300 !.
306myexclude(_Element, [], []).
307
308myexclude(Element, [OtherElement | List1], [OtherElement | List2]) :-
309 Element \= OtherElement,
310 !,
311 myexclude(Element, List1, List2).
312
313myexclude(Element, [_ | List1], List2) :-
314 myexclude(Element, List1, List2).
320setval(Name, Value) :-
321 nb_setval(Name, Value).
327getval(Name, Value) :-
328 nb_getval(Name, Value).
329
330
331:- clear_messages.
APE Error Logger (using global variables)