如何在Ada库中设置Log_Level

时间:2017-11-13 20:47:56

标签: logging ada

我在项目中第一次使用库alog。我在理解如何为所有后续日志命令设置日志级别时遇到问题。

参见我的测试程序:

with Alog;                         use Alog;
with Alog.Logger;
with Alog.Policy_DB;               use Alog.Policy_DB;

procedure Test_Loglevel
is
   L : Logger.Instance (Init => True);

   procedure Act_And_Log
   is begin
      null;
      L.Log_Message (Alog.Debug, "very detailed, only for debugging");
      null;
      L.Log_Message (Alog.Info,  "some more detailed infos");
      null;
      L.Log_Message (Alog.Notice, "general messages for interactive use");
      null;
      L.Log_Message (Alog.Warning, "something serious happened");
      null;
      L.Log_Message (Alog.Error, "error messages should always be displayed");
   end Act_And_Log;

begin
   --
   -- all logs should be displayed
   --
   Set_Loglevel ("*", Debug);
   Set_Default_Loglevel (Debug);
   Act_And_Log;
   --
   -- only error
   --
   Set_Loglevel ("*", Error);
   Set_Default_Loglevel (Error);
   Act_And_Log;

end Test_Loglevel;

我希望第一次显示所有5条消息,第二次只显示错误消息。但是,实际输出会显示5条消息两次!

如何根据严重程度过滤输出?

1 个答案:

答案 0 :(得分:0)

我直接问了alog的作者。他们回复了patch。我仍然认为该文档有点误导。