EasyLog a wrapper library for easy Log insertions

Hello Community,

I would like to share a library that we have developed in B&R Spain


General Information

Description
The EasyLog library is used to insert messages in an easy way in custom loggers. The library only contains one function (also called EasyLog) that run synchronously, so that means that in only one line it is possible to make a logger insertion. If it is the first message to insert in a logger, the function will create the logger if it doesn’t exist, also in the same call.

The EasyLog library it is based on ArEventLog (the official B&R library to make custom logger insertions). If you have ever used the ArEventLog library you know that there are a few steps before you can insert the message. Check if the logger exist, create it if don’t exist, calculate the message number, priority etc. All this steps are wrapped in a single function with the EasyLog library.

Minimum required versions

Automation Studio 4

  • From AS4.2 to AS4.12
  • From AR4.21 to AR4.93

Automation Studio 6

  • From AS6.0
  • From AR6.0

Functionality

The library EasyLog works in a very simple way. It only contains one function, called also EasyLog and has 5 inputs to fill to execute the function.

  • Execute → Boolean input. Every cycle that it is set to TRUE it will insert a message
  • LoggerName → STRING[10]. The function will check if it already exist or not, and will create this log if don’t.
  • LogLevel → Severity of the message to insert (success, info, warning or error).
  • ErrorNumber → User defined code to insert with the message.
  • Message → STRING[256]. User defined message to insert in this entry

As an output, the function only has 1 output with the Status of the execution. Any other result than ERR_OK (that is 0) should be checked in the help in order to check what has been wrong during the function execution.

Library Help

The library has its own help that comer with sample code for different examples of use. From Automation Studio can be shown by pressing F1 over the library.


Example

This is one of the examples that are available in the help. With this code the task will make one insertion every cycle of execution with the value of the process variable Temperature.

VAR
       Message : STRING[256];
       Status : DINT;
       Temperature : INT;
       TempStr : STRING[80];
       InsertMessages : BOOL;
END_VAR
PROGRAM _INIT
 
        //Set an initial message
        Message := 'TestMesage';
 
        //This will create the logger in case that does not exist in advance.
        //Only necessary if the insert time will be very fast < 5ms.
        // If logger already exist it is not necessary 
        //In that case this call with FALSE in Execute will create the logger
         // to avoid Cycle Time Violation
        Status := EasyLog(FALSE, 'Temp', arEVENTLOG_SEVERITY_INFO, 123, Message);
 
END_PROGRAM
PROGRAM _CYCLIC
 
        // Convert the current temperature into a string
        brsitoa(Temperature, ADR(TempStr));
        TempStr := CONCAT(TempStr, ' ºC');
        Message := CONCAT('Current Temperature: ', TempStr);
 
        // Execute the logger insertion if InsertMessages = TRUE
        Status := EasyLog(InsertMessages, 'Temp', arEVENTLOG_SEVERITY_INFO, 123, Message);
 
        IF Status <> ERR_OK THEN
            //Check the error in the help and solve it
        END_IF;
  
END_PROGRAM

This will be a similar result in the logger:


Downloads

Binary library V1.00.0 Version for AS4
EasyLog.zip (1.5 MB)

Binary library V1.00.0 Version for AS6
EasyLog6.zip (1.5 MB)

14 Likes
  1. Any licensing restrictions?
  2. Will the source code be available to extend/build upon?
  3. Have you run into any rate limiting issues? i.e. if you call this 10 times, each with a unique string in the same task cycle, do they appear in the logbook in the same order you called them? Example, the following code

IF executeLogging THEN
return1 := EasyLog(executeLogging,‘TestLog’,0, 0,‘Text1’);
return2 := EasyLog(executeLogging,‘TestLog’,0, 0,‘Text2’);
return3 := EasyLog(executeLogging,‘TestLog’,0, 0,‘Text3’);
return4 := EasyLog(executeLogging,‘TestLog’,0, 0,‘Text4’);
return5 := EasyLog(executeLogging,‘TestLog’,0, 0,‘Text5’);
return6 := EasyLog(executeLogging,‘TestLog’,0, 0,‘Text6’);
return7 := EasyLog(executeLogging,‘TestLog’,0, 0,‘Text7’);
return8 := EasyLog(executeLogging,‘TestLog’,0, 0,‘Text8’);
return9 := EasyLog(executeLogging,‘TestLog’,0, 0,‘Text9’);
return10 := EasyLog(executeLogging,‘TestLog’,0, 0,‘Text10’);
executeLogging := FALSE;
END_IF

Results in

Hi Matt,

Glad to see that you are interested in the library.

Answering your questions:

  1. There is no licensing limitations.
  2. The source code will not be published.
  3. We tested the library under very hard conditions to see the executions times. Of course there is a limit where you can cause a Cycle Time Violation if your cycle time is to small and with no tolerance, because as every action it take some time to get executed.
    If you have plans to write several messages in the same cycle I suggest you (as it is said also in the help) to make a call to the function in the INIT in order to create the logger in advance, and when you start to insert messages in the CYCLYC part it will be faster to execute in the first cycle (once created the logger is the same). As an example of the test that we did, in a C30 CPU (that is not very powerful CPU to be said) with a load of 80% in the CPU, it was able to write 10 messages in 4 different loggers each cycle (total of 40 messages per cycle) in a cyclic of 10ms with no tolerance without going to cycle time violation.
    And for the order questions, it is true as you put in your screenshot, the messages will appear in order.

I hope this information is useful for you :slight_smile:

3 Likes

I’ll take up the order issue with B&R support team. It makes it hard to track multiple things happening in the program if the order is messed up by writing.

Hi Matt,

Sorry I think I’m not understanding you properly. What is the problem with the order?
According to the image that you have post in your first comment it seems to work fine.

First you create the logger in the second 7:00:27,512 and after that in the execution 7:01:47:952 you insert 10 messages in the same cycle. Starting from the 1 and finishing in the 10, just like in your code.

Can you give more information?

Thank you in advance.
Best Regards

1 Like

Long story, short there was some mistakes on my end.

I had run tests with the default ArEventLog library and a library I was developing which seemed to show the messages out of order, at least when the logbook first loads. (i.e. I’ve seen it load items out of record id or timestamp order. ), but sorting by timestamp (which is how my image is ordered) or restoring default sort order, seems to display just fine.

1 Like

Good job @raul.garcia and B&R Spain

Ill save this for future use :smiley: :+1:

2 Likes

Great job @raul.garcia!! :clap:

1 Like

The source code will not be published.

Why not?

Hi @Explain5972

There may be alternatives for you here (with sources) - section ‘Tracing and logging’

https://github.com/br-automation-com/awesome-B-R

3 Likes

Hi @Explain5972,

As soon as B&R Spain is going to give support about this non official library it is not a good idea to publish the code, because in that case it will be impossible to track the modifications or changes that anyone could apply to the code.
We won’t be able to give proper support about it.

3 Likes

It is your code, so it is up to you whether you will release the source code as well. This is perfectly fine.

1 Like

Hi @Explain5972
As an additional alternative for you here (with sources), I recommend UserLog library that I use in all my prj since years: UserLog

In case you see room for improvement you can create a new branch and add your changes.

3 Likes