SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
About me
●
Thomas Aglassinger
●
Software developer
– Industry experience since 2001 in various areas (health care,
banking, e-commerce, customer relationship management)
– Casual open source developer
– 2 x MSc
●
Links
– http://www.roskakori.at
– @TAglassinger
– https://github.com/roskakori
Agenda
●
Take a look at each log level
– INFO
– ERROR
– CRITICAL
– WARNING
– DEBUG
●
When to use it?
●
Templates / guidelines for helpful log messages
INFO logging
Motivation for INFO messages
●
Quickly see what application is doing right now
(or was doing at a certain point in time)
●
Trace back what caused a certain error
●
High level
●
If possible using business terms (process,
document, file, customer record, ...)
●
Small amount of messages to avoid information
overflow and excessive impact on log storage
When to use INFO
●
With high level components: business relevant actions and decisions
that influence the result
– Business process start / end
– Input received / output sent
– Major branches in process logic
●
With low level components: essential operations
– Incoming requests
– Start / end of transactions (database, files, network, …)
– Connection to other services or resources (database)
– Important state changes ( configuration changes, log in, session context, …)
– Start / end of complex calculation, important results
– Progress information (download, calculation, ...)
Perspective of log messages
●
Word log messages from the perspective of the
application
●
I = the application
●
you = the reader of the log
●
In line with usability engineering (i.e. status
messages, progress bars, error dialogs)
ERROR logging
Detecting errors
1) Detect yourself with „if“:
2) Detect error raised by called function using
„except“:
if actual_value != expected_value:
…
try:
do_something()
except OSError as error:
...
Solving errors
●
Provide information for the log reader to reflect
about the situation that lead to an error
●
State: spell out what the data where provided /
processed
→ particularly helpful to detect slips and lapses
●
Context: spell out what the software actually was
doing
→ particularly helpful to detect lapses and
mistakes
Describing the error context
●
Message should describe the context in which the error was
detected
●
Description should be self contained
– Object that caused error, e.g. file, customer number,
session number
– Action that was attempted to be performed, e.g. reading,
writing, calculation, creating, connecting, …
– Parameters or values that were attempted to be processed
●
Previous log messages should only help to find out how this
context was reached
Template for error messages
1) Detect yourself with „if“:
2) Detect error raised by called function using
„except“:
if actual_value != expected_value:
_log.error('some value is %s but must be %s',
actual_value, expected_value)
try:
do_something()
except OSError as error:
_log.error('cannot do something: %s', error)
Variants for „detect yourself“
●
Value cannot be processed: „some value is %s but must…“
– … be between 0 and 100
– … be one of: red, green, blue
– … match format YYYY-MM-DD
●
Value not found in a large set of possible values:
– „cannot find customer number 1234“
– „cannot find customer number 1234; possible similar customer numbers: 1243, 1324“
●
Missing required value:
– „date of birth must be specified“
– „data of birth must be specified for age validation“ (explains why value is required)
●
Unterminated context of recursive descent parsers:
– „string started in line 17, column 23 must be terminated with quote“
– avoid useless “unexpected end of file”
Log or raise error?
●
Log error: Few parts of the code will log errors
– __main__ before sys.exit(1)
– self contained request handlers / dispatchers that
simply continue with next independent request
– form validation → show error and remain in form
●
Raising error:
– guidelines for wording error message apply
– can’t do anything about it anyway, just report it to the
caller
Log and raise error: anti pattern
●
Spams log with redundant and thus confusing error
messages
# BAD EXAMPLE, don't use this template
def process_customers(customers_path: str):
try:
with open(customers_path, encoding='utf-8') as customers_file:
for line in customers_file:
process_customer(line)
except OSError as error:
_log.error('cannot process customer data in "%s"', customers_path)
raise
Log and raise error: valid scenario
●
Frameworks for REST API that convert exception into
HTTP response:
1.Server raises exception
2.REST Framework converts
exception into 4xx or 5xx
HTTP response and thus
reports error to the client
3.Unless server also logs exception, information
about error would only be available to client
Further reading on error handling
●
Lösungsorientierte Fehlerbehandlung (with
Python)
●
How to write good error messages (with many
examples)
CRITICAL messages
Critical errors
●
When application has to exit in unclean manner
– Resource leaks
– Data loss
●
Typical before involuntary server shutdown
●
Inappropriate for:
– Unprocessable single request / command / user input
– Errors during program startup, e.g. missing command
line option or broken syntax in configuration file
Wording critical messages
CRITICAL: cannot reconnect to database some.db: <some database error>
INFO: shutting down server
●
Messages worded similar to ERROR
●
Example:
WARNING messages
Warnings hint at design issues
●
INFO is „good“
●
ERROS is „bad“
●
WARNING is …?
Wording warnings
●
Mix of error and info should reflect in the wording
●
Error part: describes what happened and was
expected
●
Info part: describes what is being done / has been
done to improve the situation
Transient errors
●
External errors that might be going away after a
while because the cause went away
●
Might be able to solve with retries
●
Example:
WARNING:example: Cannot connect to database some.db, trying
to reconnect (attempt 2 of 5)
Reduced quality of service
●
In environment with multiple redundant
components that can perform the same task
●
Example:
– replicas of search platform
– stateless micro services
request
Reduced quality of service
●
In environment with multiple redundant
components that can perform the same task
●
Example:
– replicas of search platform
– stateless micro services
●
Example:
request
WARNING:example: Cannot connect to search
server abcd17. Temporarily removing server from
pool and delegating request to server abcd18
DEBUG messages
Debug messages
●
Target audience
– debug: developers familiar with the code
– any other log level: devops, operations, users, …
●
Wording
– if possible similar to INFO
– otherwise: whatever rocks your boat
●
names of classes, methods, variables
●
dumps of XML, JSON, request headers
●
escaped string, hexadecimal garble
●
...
Enabling debug logging
●
Only temporarily while tracking down an issue
●
Otherwise: too much strain on storage and
collection of logs
●
Enable only for loggers that are expected to
contain relevant information
●
Consider adding a mechanic to your application
that allows to change log levels during runtime
Conclusion
Summary
●
INFO:
– “doing” vs “did“
– Focus on business logic
– Keep amount of messages low
●
ERROR:
– “cannot do something: something must be something else“
– Log vs raise, avoid log and raise
●
CRITICAL: like error but only if the application cannot recover
●
WARNING
– Might hint at design issues
– Few valid situations
– Combines error and info message
●
DEBUG
– For developers
– Log whatever is necessary
Questions and answers
Thomas Aglassinger
http://www.roskakori.at
@TAglassinger

Contenu connexe

Tendances (20)

JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Controls
ControlsControls
Controls
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
 
AtoM's Command Line Tasks - An Introduction
AtoM's Command Line Tasks - An IntroductionAtoM's Command Line Tasks - An Introduction
AtoM's Command Line Tasks - An Introduction
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Input output streams
Input output streamsInput output streams
Input output streams
 
URL Class in JAVA
URL Class in JAVAURL Class in JAVA
URL Class in JAVA
 
Windows form application_in_vb(vb.net --3 year)
Windows form application_in_vb(vb.net --3 year)Windows form application_in_vb(vb.net --3 year)
Windows form application_in_vb(vb.net --3 year)
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
Sending emails through PHP
Sending emails through PHPSending emails through PHP
Sending emails through PHP
 
php
phpphp
php
 
Sql
SqlSql
Sql
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Jquery library
Jquery libraryJquery library
Jquery library
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Xml http request
Xml http requestXml http request
Xml http request
 

Similaire à Helpful logging with python

Helpful logging with Java
Helpful logging with JavaHelpful logging with Java
Helpful logging with Javaroskakori
 
EDD (Error Driven Development)
EDD (Error Driven Development)EDD (Error Driven Development)
EDD (Error Driven Development)Daniel Andrews
 
Building of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingBuilding of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingPVS-Studio
 
Application Logging Good Bad Ugly ... Beautiful?
Application Logging Good Bad Ugly ... Beautiful?Application Logging Good Bad Ugly ... Beautiful?
Application Logging Good Bad Ugly ... Beautiful?Anton Chuvakin
 
TDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit HappensTDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit HappensJackson F. de A. Mafra
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Testdecatv
 

Similaire à Helpful logging with python (20)

Helpful logging with Java
Helpful logging with JavaHelpful logging with Java
Helpful logging with Java
 
Api presentation
Api presentationApi presentation
Api presentation
 
EDD (Error Driven Development)
EDD (Error Driven Development)EDD (Error Driven Development)
EDD (Error Driven Development)
 
Building of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingBuilding of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code logging
 
Application Logging Good Bad Ugly ... Beautiful?
Application Logging Good Bad Ugly ... Beautiful?Application Logging Good Bad Ugly ... Beautiful?
Application Logging Good Bad Ugly ... Beautiful?
 
TDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit HappensTDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit Happens
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 
API Upload Test
API Upload TestAPI Upload Test
API Upload Test
 

Plus de roskakori

Expanding skill sets - Broaden your perspective on design
Expanding skill sets - Broaden your perspective on designExpanding skill sets - Broaden your perspective on design
Expanding skill sets - Broaden your perspective on designroskakori
 
Django trifft Flutter
Django trifft FlutterDjango trifft Flutter
Django trifft Flutterroskakori
 
Multiple django applications on a single server with nginx
Multiple django applications on a single server with nginxMultiple django applications on a single server with nginx
Multiple django applications on a single server with nginxroskakori
 
Helpful pre commit hooks for Python and Django
Helpful pre commit hooks for Python and DjangoHelpful pre commit hooks for Python and Django
Helpful pre commit hooks for Python and Djangoroskakori
 
Startmeeting Interessengruppe NLP NLU Graz
Startmeeting Interessengruppe NLP NLU GrazStartmeeting Interessengruppe NLP NLU Graz
Startmeeting Interessengruppe NLP NLU Grazroskakori
 
Einführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Einführung in Kommunikation und Konfliktmanagement für Software-EntwicklerEinführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Einführung in Kommunikation und Konfliktmanagement für Software-Entwicklerroskakori
 
Analyzing natural language feedback using python
Analyzing natural language feedback using pythonAnalyzing natural language feedback using python
Analyzing natural language feedback using pythonroskakori
 
Microsoft SQL Server with Linux and Docker
Microsoft SQL Server with Linux and DockerMicrosoft SQL Server with Linux and Docker
Microsoft SQL Server with Linux and Dockerroskakori
 
Migration to Python 3 in Finance
Migration to Python 3 in FinanceMigration to Python 3 in Finance
Migration to Python 3 in Financeroskakori
 
Introduction to pygments
Introduction to pygmentsIntroduction to pygments
Introduction to pygmentsroskakori
 
Lösungsorientierte Fehlerbehandlung
Lösungsorientierte FehlerbehandlungLösungsorientierte Fehlerbehandlung
Lösungsorientierte Fehlerbehandlungroskakori
 
XML namespaces and XPath with Python
XML namespaces and XPath with PythonXML namespaces and XPath with Python
XML namespaces and XPath with Pythonroskakori
 
Erste-Hilfekasten für Unicode mit Python
Erste-Hilfekasten für Unicode mit PythonErste-Hilfekasten für Unicode mit Python
Erste-Hilfekasten für Unicode mit Pythonroskakori
 
Introduction to trader bots with Python
Introduction to trader bots with PythonIntroduction to trader bots with Python
Introduction to trader bots with Pythonroskakori
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with pythonroskakori
 
Python builds mit ant
Python builds mit antPython builds mit ant
Python builds mit antroskakori
 
Kanban zur Abwicklung von Reporting-Anforderungen
Kanban zur Abwicklung von Reporting-AnforderungenKanban zur Abwicklung von Reporting-Anforderungen
Kanban zur Abwicklung von Reporting-Anforderungenroskakori
 

Plus de roskakori (17)

Expanding skill sets - Broaden your perspective on design
Expanding skill sets - Broaden your perspective on designExpanding skill sets - Broaden your perspective on design
Expanding skill sets - Broaden your perspective on design
 
Django trifft Flutter
Django trifft FlutterDjango trifft Flutter
Django trifft Flutter
 
Multiple django applications on a single server with nginx
Multiple django applications on a single server with nginxMultiple django applications on a single server with nginx
Multiple django applications on a single server with nginx
 
Helpful pre commit hooks for Python and Django
Helpful pre commit hooks for Python and DjangoHelpful pre commit hooks for Python and Django
Helpful pre commit hooks for Python and Django
 
Startmeeting Interessengruppe NLP NLU Graz
Startmeeting Interessengruppe NLP NLU GrazStartmeeting Interessengruppe NLP NLU Graz
Startmeeting Interessengruppe NLP NLU Graz
 
Einführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Einführung in Kommunikation und Konfliktmanagement für Software-EntwicklerEinführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Einführung in Kommunikation und Konfliktmanagement für Software-Entwickler
 
Analyzing natural language feedback using python
Analyzing natural language feedback using pythonAnalyzing natural language feedback using python
Analyzing natural language feedback using python
 
Microsoft SQL Server with Linux and Docker
Microsoft SQL Server with Linux and DockerMicrosoft SQL Server with Linux and Docker
Microsoft SQL Server with Linux and Docker
 
Migration to Python 3 in Finance
Migration to Python 3 in FinanceMigration to Python 3 in Finance
Migration to Python 3 in Finance
 
Introduction to pygments
Introduction to pygmentsIntroduction to pygments
Introduction to pygments
 
Lösungsorientierte Fehlerbehandlung
Lösungsorientierte FehlerbehandlungLösungsorientierte Fehlerbehandlung
Lösungsorientierte Fehlerbehandlung
 
XML namespaces and XPath with Python
XML namespaces and XPath with PythonXML namespaces and XPath with Python
XML namespaces and XPath with Python
 
Erste-Hilfekasten für Unicode mit Python
Erste-Hilfekasten für Unicode mit PythonErste-Hilfekasten für Unicode mit Python
Erste-Hilfekasten für Unicode mit Python
 
Introduction to trader bots with Python
Introduction to trader bots with PythonIntroduction to trader bots with Python
Introduction to trader bots with Python
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
 
Python builds mit ant
Python builds mit antPython builds mit ant
Python builds mit ant
 
Kanban zur Abwicklung von Reporting-Anforderungen
Kanban zur Abwicklung von Reporting-AnforderungenKanban zur Abwicklung von Reporting-Anforderungen
Kanban zur Abwicklung von Reporting-Anforderungen
 

Dernier

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Dernier (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Helpful logging with python

  • 1.
  • 2. About me ● Thomas Aglassinger ● Software developer – Industry experience since 2001 in various areas (health care, banking, e-commerce, customer relationship management) – Casual open source developer – 2 x MSc ● Links – http://www.roskakori.at – @TAglassinger – https://github.com/roskakori
  • 3.
  • 4. Agenda ● Take a look at each log level – INFO – ERROR – CRITICAL – WARNING – DEBUG ● When to use it? ● Templates / guidelines for helpful log messages
  • 6. Motivation for INFO messages ● Quickly see what application is doing right now (or was doing at a certain point in time) ● Trace back what caused a certain error ● High level ● If possible using business terms (process, document, file, customer record, ...) ● Small amount of messages to avoid information overflow and excessive impact on log storage
  • 7. When to use INFO ● With high level components: business relevant actions and decisions that influence the result – Business process start / end – Input received / output sent – Major branches in process logic ● With low level components: essential operations – Incoming requests – Start / end of transactions (database, files, network, …) – Connection to other services or resources (database) – Important state changes ( configuration changes, log in, session context, …) – Start / end of complex calculation, important results – Progress information (download, calculation, ...)
  • 8.
  • 9.
  • 10. Perspective of log messages ● Word log messages from the perspective of the application ● I = the application ● you = the reader of the log ● In line with usability engineering (i.e. status messages, progress bars, error dialogs)
  • 12. Detecting errors 1) Detect yourself with „if“: 2) Detect error raised by called function using „except“: if actual_value != expected_value: … try: do_something() except OSError as error: ...
  • 13.
  • 14. Solving errors ● Provide information for the log reader to reflect about the situation that lead to an error ● State: spell out what the data where provided / processed → particularly helpful to detect slips and lapses ● Context: spell out what the software actually was doing → particularly helpful to detect lapses and mistakes
  • 15. Describing the error context ● Message should describe the context in which the error was detected ● Description should be self contained – Object that caused error, e.g. file, customer number, session number – Action that was attempted to be performed, e.g. reading, writing, calculation, creating, connecting, … – Parameters or values that were attempted to be processed ● Previous log messages should only help to find out how this context was reached
  • 16. Template for error messages 1) Detect yourself with „if“: 2) Detect error raised by called function using „except“: if actual_value != expected_value: _log.error('some value is %s but must be %s', actual_value, expected_value) try: do_something() except OSError as error: _log.error('cannot do something: %s', error)
  • 17. Variants for „detect yourself“ ● Value cannot be processed: „some value is %s but must…“ – … be between 0 and 100 – … be one of: red, green, blue – … match format YYYY-MM-DD ● Value not found in a large set of possible values: – „cannot find customer number 1234“ – „cannot find customer number 1234; possible similar customer numbers: 1243, 1324“ ● Missing required value: – „date of birth must be specified“ – „data of birth must be specified for age validation“ (explains why value is required) ● Unterminated context of recursive descent parsers: – „string started in line 17, column 23 must be terminated with quote“ – avoid useless “unexpected end of file”
  • 18. Log or raise error? ● Log error: Few parts of the code will log errors – __main__ before sys.exit(1) – self contained request handlers / dispatchers that simply continue with next independent request – form validation → show error and remain in form ● Raising error: – guidelines for wording error message apply – can’t do anything about it anyway, just report it to the caller
  • 19. Log and raise error: anti pattern ● Spams log with redundant and thus confusing error messages # BAD EXAMPLE, don't use this template def process_customers(customers_path: str): try: with open(customers_path, encoding='utf-8') as customers_file: for line in customers_file: process_customer(line) except OSError as error: _log.error('cannot process customer data in "%s"', customers_path) raise
  • 20.
  • 21. Log and raise error: valid scenario ● Frameworks for REST API that convert exception into HTTP response: 1.Server raises exception 2.REST Framework converts exception into 4xx or 5xx HTTP response and thus reports error to the client 3.Unless server also logs exception, information about error would only be available to client
  • 22. Further reading on error handling ● Lösungsorientierte Fehlerbehandlung (with Python) ● How to write good error messages (with many examples)
  • 24. Critical errors ● When application has to exit in unclean manner – Resource leaks – Data loss ● Typical before involuntary server shutdown ● Inappropriate for: – Unprocessable single request / command / user input – Errors during program startup, e.g. missing command line option or broken syntax in configuration file
  • 25. Wording critical messages CRITICAL: cannot reconnect to database some.db: <some database error> INFO: shutting down server ● Messages worded similar to ERROR ● Example:
  • 27. Warnings hint at design issues ● INFO is „good“ ● ERROS is „bad“ ● WARNING is …?
  • 28.
  • 29.
  • 30. Wording warnings ● Mix of error and info should reflect in the wording ● Error part: describes what happened and was expected ● Info part: describes what is being done / has been done to improve the situation
  • 31. Transient errors ● External errors that might be going away after a while because the cause went away ● Might be able to solve with retries ● Example: WARNING:example: Cannot connect to database some.db, trying to reconnect (attempt 2 of 5)
  • 32. Reduced quality of service ● In environment with multiple redundant components that can perform the same task ● Example: – replicas of search platform – stateless micro services request
  • 33. Reduced quality of service ● In environment with multiple redundant components that can perform the same task ● Example: – replicas of search platform – stateless micro services ● Example: request WARNING:example: Cannot connect to search server abcd17. Temporarily removing server from pool and delegating request to server abcd18
  • 35. Debug messages ● Target audience – debug: developers familiar with the code – any other log level: devops, operations, users, … ● Wording – if possible similar to INFO – otherwise: whatever rocks your boat ● names of classes, methods, variables ● dumps of XML, JSON, request headers ● escaped string, hexadecimal garble ● ...
  • 36.
  • 37. Enabling debug logging ● Only temporarily while tracking down an issue ● Otherwise: too much strain on storage and collection of logs ● Enable only for loggers that are expected to contain relevant information ● Consider adding a mechanic to your application that allows to change log levels during runtime
  • 39. Summary ● INFO: – “doing” vs “did“ – Focus on business logic – Keep amount of messages low ● ERROR: – “cannot do something: something must be something else“ – Log vs raise, avoid log and raise ● CRITICAL: like error but only if the application cannot recover ● WARNING – Might hint at design issues – Few valid situations – Combines error and info message ● DEBUG – For developers – Log whatever is necessary
  • 40. Questions and answers Thomas Aglassinger http://www.roskakori.at @TAglassinger