logging - User defined log filename in Ada - Stack Overflow

The following compileswith Util.Log.Loggers;package body LogTest isLog : constant Util.Log.Loggers.Log

The following compiles

with Util.Log.Loggers;

package body LogTest is

   Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create("./abc.log");
   ...
end LogTest;

The problem is that I need to read in the filename from a configuration file so I tried

package body LogTest is
   Log: Util.Log.Loggers.Logger;

   procedure LogTestInit(filename : String) is
   begin
      Log := Util.Log.Loggers.Create(filename);
   end LogTestInit;

but it comes up with left hand side of assignment must not be limited type. Two questions

  1. What should I do if I wish to pass in the filename? How do I create the log instance.
  2. Why does the assignment work in the first case but not in the second?

The following compiles

with Util.Log.Loggers;

package body LogTest is

   Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create("./abc.log");
   ...
end LogTest;

The problem is that I need to read in the filename from a configuration file so I tried

package body LogTest is
   Log: Util.Log.Loggers.Logger;

   procedure LogTestInit(filename : String) is
   begin
      Log := Util.Log.Loggers.Create(filename);
   end LogTestInit;

but it comes up with left hand side of assignment must not be limited type. Two questions

  1. What should I do if I wish to pass in the filename? How do I create the log instance.
  2. Why does the assignment work in the first case but not in the second?
Share asked Mar 3 at 20:00 cupcup 8,3214 gold badges22 silver badges44 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Off the top of my head:

  1. Create a function which by some appropriate means determines the required filename and returns that.
  2. In the first case, a new Loggers.Logger is being initialised with the function result. In the second case, there’s already a limited Loggers.Logger, and you’re trying to assign to it.

I've since found that the string passed in

Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create("./abc.log");

is not a filename but an identification tag, so it can be a hard coded constant, or, as @simonwright hinted, a function that returns a string. If there are multiple tasks or packages, each can have its own tag. The actual log filename is set in the configuration file that is passed to the Initialize function.

For C# people, limited means it is not ICloneable.

For C++ people, limited means it is a non-copyable object.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745074557a4609754.html

相关推荐

  • logging - User defined log filename in Ada - Stack Overflow

    The following compileswith Util.Log.Loggers;package body LogTest isLog : constant Util.Log.Loggers.Log

    14小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信