introduction to logging regulatory or legal compliance in some cases records of program execution may be required for regulatory or legal reasons this is particularly true of the financial sector where records must be kept for many years in case there is need to investigate the organisationsor individualsbehaviour what is the purpose of loggingin general there are therefore two general reason to log what an application is doing during it operationfor diagnostic purposes so that recorded events/steps can be used to analyse the behaviour of the system when something goes wrong auditing purposes that allow for later analysis of the behaviour of the system for businesslegal or regulatory purposes for examplein this case to determine who did what with what and when without such logged information it is impossible after the event to know what happened for exampleif all you know is that an application crashed (unexpectedly stopped executinghow can you determine what state the application was inwhat functionsmethods etc were being executed and which statements runremember that although developer may have been using an ide to run their applications during development and may possibly been using the debugging facilities available that allow you to see what functions or methodsstatements and even variable values are placethis is not how most production systems are run in general production python system will be run either from command line or possibly through short cut (on windows boxto simplify running the program all the user will know is that something failed or that the behaviour they expected didn' occur--if in fact they are aware of any issue at alllogs are therefore key to after the event analysis of failuresunexpected behaviour or for analysis of the operation of the system for business reasons what should you logone question that you might be considering at this point is 'what information should log?an application should log enough information so that post event investigators can understand what was happeningwhen and where in general this means that you will want to log the time of the log messagethe module/filenamefunction name or method name executingpotentially the log level being used (see laterand in some cases the parameter values/state of the environmentprogram or class involved