RPA - Logging is your best friend
This is about a 5 minute read.
Why post about something so boring and trivial, like logging, that every one does? Because i have found not a lot of people do it much or perhaps use it at a minimum level. This post is probably more aimed at those starting out or people who have come to RPA from a non-programming background. It is only an opinion, but it might be useful for some, and will likely save hours of frustration when your bot is not doing what you want it to.
The Basic premise is: log a LOT; log a LOT of info and make your logging multi level i.e. levels of verbosity
TL;DR
The proposal is that if one is pedantic and detailed about logging in bots, instead of perhaps finding it a bore to add in once the bot is written, it will save considerable time, effort and be the most effective debugging tool anyone needs. It will also make your bots more maintainable. So, if you are interested in the possibilities, read on.
Is the above an obvious statement? Yup, but time and time again when I have viewed logs from bots, they have been practically pointless or useless.
For this post I am going to focus on what is often called the event log i.e. the continuing log of stuff happening in the bot. Error logs etc are pretty self-explanatory (or should be :-) ).
Why do this?
Consider the following scenarios (there are many more):
Are there benefits ? (some examples)
So, in summary, if we insert logging as we write (and we make it really easy to do), it is no effort and will pay back countless times. Seems like a no-brainer to me. I am often curious why people don't and apply logging (and commenting) after writing the module - which I personally find to be a real bore.
Some suggestions on approach
1. You can't log enough (logging levels)
Some would argue this is a silly statement as your logs become crammed with thousands of lines of unintelligible data AND in production the logs will chew up a lot of disk space over time. Here is the proposition:
2. Have a really good format and very informative columns
So many times I have seen something like:
(19/09/2021 06:45:00) Some arbitrary text which may have some insight in it or not
This is usually because someone has just done a LOG TO FILE "Some arbitrary text which may have some insight in it", with perhaps "APPEND DATE & TIME" set as an option. In my humble opinion this is of no help, try the following
Have some really good columns e.g.
Date, Time, Logging Level, Process (e.g. overall Bot name), Module (e.g. , workflow etc. in UiPath [i.e. the .xaml name] or task file name in AA), Machine, Type (an arbitrary class of the log entry), System (e.g. the system being automated), Item (the unique item being processed e.g. an Invoice number or PDF file etc.), Message (the log message), Extra Data and anything else you need that is specific to the RPA platform which would be useful
Recommended by LinkedIn
Use a decent file format
Straight text is all very well and good but pretty useless if you are analysing logs, so a delimited format would be better. I find CSV difficult to read when scrolling through so I favour Tab delimited as the columns are separated better when viewed in an editor
Both CSV and TSV can then be viewed in anything as raw text or even loaded into excel so it can be filtered, analysed etc. Allowing flexibility of viewing tool makes things so convenient.
A log file should be viewable in just about anything, minimum being notepad. What I love to use is VS Code with the Rainbow CSV plugin which colour codes each column and will allow column view (each a column is aligned) or normal. As a side note I try not to use excel to view CSV files anyway because what you see is not necessarily what is in the file. VS Code also allows tailing of the log (auto scroll to end) and has the file open without a conflict with the bot writing to it. I am sure these things exist in all the other text editors.
Allow plenty of detail
As an example, I prefer to include milliseconds in the time. The only reason is that I like to optimise the bot's speed and have also often been challenged on the performance implications of breaking a bot up into lots of re-usable .xamls or sub tasks.
I also try to make the message as descriptive as possible, in natural language instead of tech and possibly include data to assist.
2. Build your own re-usable logging component (if necessary)
In UiPath there is a very sophisticated logging framework which should also upload to Orchestrator. You may also wish to supplement this, but at least ensure that you are using all the levels and fields appropriately. You may still want to write a small logging module which makes sure all fields are added and it is simple to log. This will give you standardisation across your bots
If you are not using UiPath and your RPA Platform doesn't have a specific logging framework, that is not necessarily a bad thing. The simple answer is to build your own logging module that deals with all parts of logging and then you can be in the happy place of copy and paste every time you need to log. Seems obvious, but many times I have seen bots with the same repeated custom lines of log to file, which are murder to change throughout all the modules.
While you are at it, make the logging module standalone so it will create a file if not there, add to a file if there and deal with how you want to organise your logs. You could have one file per day and even have an archive folder which it moves old ones into. Also think ahead for the scenarios where your bot may run on a device pool (i.e. run on any bot runner in that pool), so create a directory structure that ensures that bots don't overwrite other bots' logs. I go a bit over the top with [Process Name]\[Production Mode (Dev, UAT, Prod)]\Machine Name, as it can help if your bot also copies logs to a shared drive, i.e. no files get overwritten.
As a personal choice I try and avoid having a year\month\day logging folder structure as I find it tedious to navigate through, but it seems to be a very popular approach. I tend to favour a log file with a time stamp in the name (i.e. one per day) then an archive folder below that.
Mixing Events and Errors in the event log
The Automation Anywhere best practise document suggests having an event log and a separate Error log. This is sensible as it is quicker to read through the Error log if there is a problem. I personally choose to log the error to the event log too as it then gives you context for when the Error occurs i.e. what the bot did before and after.
3. Make a standard approach part of your coding standards
Peer review of code is an important part of a bot deployment process. It will help a great deal to ensure that all bot writers stick to those standards and log to the degree which enables better maintenance and problem diagnosis.
4. Have standard a diagnosis approach for when a bot is in production and problems occur
This will depend on your RPA platform, e.g. in UiPath you can go to Orchestrator and start drilling down. If you have built your own logging module then the process may include changing config to turn on a more verbose logging level and re-running the bot. This means the Bot operations team can gather all the diagnosing information, fix things if the problem is outside of a bot or raise the problem to the right owner (i.e. the bot developer or application/data owner)
It is also important to have a very good error handler module which takes care of logging as much info as possible about the error, whether it is an error or business (data etc.) exception, what the bot does etc., depending on whether the error is fatal/critical or just for one transaction etc.
Summary
So, there you have it, the pedantic view of how to use logging in your bot. I have no idea whether this post is informative or patronising but if it helps someone then all is good. In Summary
Perhaps I should have posted just the above bullets, but I promise it will save you time and effort.
Writer @TheCodingTheory | Certified RPA Developer
3yI never gave much thought to logging other than just the timestamp and semi-descriptive message. What you said is absolutely true, and it needs to be more descriptive. I have learnt a lot from this post of yours, and am looking forward to more 🙂
RPA Untangelist at SmartRPA
3yI'm not a UIpath user, but this is very important if you like to improve the ROI. When done right, it can lift the setup to a new level. Unfortunately most people doesn't spend time on this in the buildup phase, as this problem isn't visable until multiple robots needs maintenance and you have zero clue why they are failing. A few things I wanted to add: 1. Writing to a file is not scalable, a database is the only scalable choice for debug logs. If you make a standalone action/function for storing logs, create a database and save the trouble text file versioning and archiving gives. 2. Logs will also be used to backtrack false-positive items/cases which was run x-weeks ago. Here it's important to be able to know start and stop for the items/cases in the malfunctioning process. Meaning that the logs needs to be process specific and being able to point to start or end of the specific item/case. P.s. I might be wrong on some of the things I said, I did read it a bit fast, so I can have skipped some important points. Sorry in advance. P.p.s. I'm a BP user, so logging is build into the actions, here the problem is to minimize logging as diskusage gets HUGE quite quickly. *There is no such thing, as a free lunch*
Staff Intelligent Automation Engineer
3yThanks for sharing!
🌱 Raising Pre-Seed (SEIS) 👉 Founder @SilkFlo.com | Innovation SaaS Helping Enterprises Find High-Impact AI Use Cases, Assess Costs and Track ROI.
3yLove this. Thanks for writing this Simon!