3

I made 2 loggers, one for each thread like this(THREAD=2):

lsd_logger[THREADS]      : list of message_logger is instance; 
  keep for each in lsd_logger {
      soft it.tags      == {appendf("DBG%d",index).as_a(message_tag)};
      it.to_file        == appendf("lsd%d.elog", index);
      soft it.verbosity == HIGH;
      it.to_screen == FALSE;
  };

Now I have a checker that I want to sent a message to each logger according to the thread currently running, like this:

messagef(appendf("DBG%d",thread).as_a(message_tag), MEDIUM, "this is a message to logger %d",thread);

But I keep getting this error about how this is not a constant verbosity.

Is there a way to give the message_tag like this instead of creating a func to handle the printing?

Thank you,

O. San
  • 1,107
  • 3
  • 11
  • 25
  • 1
    Have you extended the `message_tag` type with all possible tags, `DBG0`, `DBG1` and so on? – Thorsten Jan 21 '16 at 08:44
  • Thank you for your help! Yes, I even added them explicit my name [DBG0,DBG1]. Also when I send a message with hard-coded message-tag (DBG0 for instance) it works wonderfully... – O. San Jan 21 '16 at 13:05

1 Answers1

3

No, this is impossible. The tag of the message must be hard-coded, thus it should be a constant tag, and not any expression that returns a tag.

You could possibly solve the issue by defining a method like this:

my_message() is {
    case thread {
        0: {
            messagef(DBG0, MEDIUM, "this is a message to logger 0");
           };
        1: {
            messagef(DBG1, MEDIUM, "this is a message to logger 1");
           };
    };
};

Then if you want to avoid writing this very long method with repeating code (which you even need to modify every time the number of threads changes), you can use a define as computed macro instead, such as:

define <my_message'action> "my_message" as computed {
    items: list of string;
    for i from 0 to THREADS-1 do {
        items.add(appendf("%d: {messagef(DBG%d, MEDIUM, \"this is a message to logger %d\")}", i, i, i));
    };
    result = appendf("case thread { %s }", str_join(items, ";"));
};
Yuri Tsoglin
  • 963
  • 4
  • 7
  • Thank you very much for your answer! Can you think of a way to still make it work in this manner without creating a function? Perhaps something other than messagef? Thank you, – O. San Jan 21 '16 at 13:08
  • 1
    @yuri do you know why that is? Is `messagef()` a macro? – Thorsten Jan 21 '16 at 15:51
  • 1
    @Thorsten This is because a tag is considered an integral part of the message in the code, and not just a value computed at run time. For example, tags are used to modify message settings. When this is done, each particular message is being set to be sent or not sent to a given destination according to its tag. There are also certain optimizations based on that, for example, a message is marked as completely inactive if its tag is set off by all units and for all destinations. – Yuri Tsoglin Jan 21 '16 at 17:12
  • 1
    @O.San I have added a suggestion to my previous answer. Hope it helps. – Yuri Tsoglin Jan 21 '16 at 17:30