Question

timestamp format in log action

  • 25 October 2023
  • 5 replies
  • 107 views

Badge +3

How can i change that format of the log to file action → append timestamp


5 replies

Userlevel 3
Badge +8

Hi @mohammad_al-hajj,

If I understand your query right, you looking to change the log format. you can achieve it by changing the property line “<Property name="FormatPatternSingleLine">...</Property>” in the bot agent config files which are located at “C:\Program Files\Automation Anywhere\Bot Agent\config”

nodemanager-logging.xml 
botlauncher-logging.xml 
triggerlistener-logging.xml 
autologinhelper-logging.xml   
 

You can customize the log format pattern according to your requirements as mentioned here- https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html

Badge +3

Hi @ravi.pothana ,

Thank you for the reply.

To my knowledge, these are system generated log files. I want to change the format of the “append timestamp” in the “log to file action” in the bot editor. Please use the picture as reference.

Log to file action - package version 3.4.0

The current log timestamp format is “(M/d/yyyy h:m:s a)”

Example:

(9/28/2023 2:48:31 PM) XXXXXX - BOT STARTED
I want to change it to change it to “yyyy-MM-dd HH:mm:ss”

I tried using the Date:toSting action, but it is not convenient. It also has the tendency to add milliseconds with no specified decimal point cutoff. I have to define the conversion log format manually every time to go around this behavior. Plus, if adds an extra line of code for every time I want to log. We don’t want to use log files with different timestamp lengths. It makes debugging harder.

Example of my attempt

Finally, Is there a way for me to define a log level (debug, warning, info,….) per “log to file” action? I am currently adding the level by hand.

Userlevel 6
Badge +15

Hi @mohammad_al-hajj ,

Kindly try the below option,

  • Uncheck the append timestamp 
  • add the  below code into the Enter text to log $System:Year.Number:toString$-$System:Month.Number:toString$-$System:day.Number:toString$ $System:hour.Number:toString$:$System:Minute.Number:toString$:$System:Second.Number:toString$ 

Following above steps, you can log the details with required format. Would you like to add any additional info you can add it as well. 

 

Example

$System:Year.Number:toString$-$System:Month.Number:toString$-$System:day.Number:toString$ $System:hour.Number:toString$:$System:Minute.Number:toString$:$System:Second.Number:toString$ $PRCS-ProcessName$ ORB3 Process - Started

 

 

 

 
Badge +3

$System:Year.Number:toString$-$System:Month.Number:toString$-$System:day.Number:toString$ $System:hour.Number:toString$:$System:Minute.Number:toString$:$System:Second.Number:toString$ $PRCS-ProcessName$ ORB3 Process - Started

 

 Hi @Tamil Arasu10 ,

Thank you for your reply.

We are aware of the solution you present and thank you for pointing it out to us. We are looking for a more elegant solution. We do not want our developers to add this much boilerplate code on every log call. We would prefer to use the built in checkbox instead since it already exists.

Also, please note that in rare situations your code will return the wrong time since you are fetching each part of it on it’s own. It is better to fetch the whole date from System:Date and then apply a Date::toString() action on it. This will guarantee a consistent result.

Our main question still stands however. Is there a way to control the behavior of the “log to file” → “append timestamp” action?

Badge +3

@mohammad_al-hajj Yes, it’s possible.

Log to file action checks for system’s regional short date and short time settings to generate the time format. If you change these in system, it will reflect in your log files.

You can change them from following registry keys:

Location: Computer\HKEY_CURRENT_USER\Control Panel\International

Keys: 

  • sTimeFormat
  • sShortDate

 

I suggest looking into package SDK to build something as per your requirements.


AA pre built logging action is trivial. Even though log variables options was added recently, it still cant log complex/ nested variables like list, dictionary, table, record or list of dictionaries etc. You need to convert to string through legacy package(which AA discourages in new bot builds) and is difficult to read/not sure if actual escape character or data. Also it lacks file rollover based on size/time etc.

 

 

 
 

Reply