SlideShare a Scribd company logo
1 of 51
Download to read offline
Why use logging

Basics

When to use what?

Logbook

Logging in Python
For complex applications

Fayaz Yusuf Khan

20 December 2013

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Why use logging?

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Why use logging?

• All errors happen in runtime.

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Why use logging?

• All errors happen in runtime.
• Testing can never be 100%

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

import logging
logging . warning ( ’ Watch out ! ’) # will print a message
logging . info ( ’I told you so ’) # will not print a n y t h i n g

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

import logging
logging . warning ( ’ Watch out ! ’) # will print a message
logging . info ( ’I told you so ’) # will not print a n y t h i n g

Output:
WARNING:root:Watch out!

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Logging to a file

import logging
logging . basicConfig ( filename = ’ example . log ’ ,
level = logging . DEBUG )
logging . debug ( ’ This message should go to the log file ’)
logging . info ( ’ So should this ’)
logging . warning ( ’ And this , too ’)

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Logging to a file

import logging
logging . basicConfig ( filename = ’ example . log ’ ,
level = logging . DEBUG )
logging . debug ( ’ This message should go to the log file ’)
logging . info ( ’ So should this ’)
logging . warning ( ’ And this , too ’)

Output:
DEBUG:root:This message should go to the log file
INFO:root:So should this
WARNING:root:And this, too

The end
Why use logging

Basics

When to use what?

Logbook

Initializing

logger = logging . getLogger ( __name__ )

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

The end

print()

Display console output for ordinary usage of a command line script
or program
Why use logging

Basics

When to use what?

Logbook

Error reporting

logging.info()

Report events that occur during normal operation of a program
(e.g. for status monitoring or fault investigation)

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

logging.debug()

Very detailed output for diagnostic purposes

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

warnings.warn()

In library code if the issue is avoidable and the client application
should be modified to eliminate the warning.

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

logging.warning()

If there is nothing the client application can do about the
situation, but the event should still be noted

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Report an error regarding a particular runtime event

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Raise an exception

Report an error regarding a particular runtime event

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

logging.error() or logging.exception()

Report suppression of an error without raising an exception (e.g.
error handler in a long-running server process)

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

The end

logging.critical()

A serious error, indicating that the program itself may be unable to
continue running.
Why use logging

Basics

When to use what?

Logbook

Error reporting

Logbook
pythonhosted.org/Logbook

Logbook is a logging sytem for Python that replaces the standard
library’s logging module.

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

>>> from logbook import Logger
>>> log = Logger ( ’ Logbook ’)
>>> log . info ( ’ Hello , World ! ’)
[2010 -07 -23 16:34] INFO : Logbook : Hello , World !

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Context managers everywhere!

from logbook import SyslogHandler
error_handler = SyslogHandler ( ’ logbook example ’ ,
level = ’ ERROR ’)
with error_handler . a p p l i c a t i o n b o u n d ():
# wh a t e v e r is e x e c u t e d here and an error is logged to
# the error handler
...

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Getting your libraries and old code to behave

from logbook . compat import r e d i r ec t _ l o g g i n g
r e d i r e ct _ l o g g i n g ()

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Injecting context

import os
from logbook import Processor
def inject_cwd ( record ):
record . extra [ ’ cwd ’] = os . getcwd ()
with my_handler . a p p l i c at i o n b o u n d ():
with Processor ( inject_cwd ). a p p l i c a t i o n b o u n d ():
# e v e r y t h i n g logged here will have the current
# working d i r e c t o r y in the log record .
...

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Formatting in Logging

import logging
logging . basicConfig ( format = ’ %( levelname ) s :%( message ) s ’ ,
level = logging . DEBUG )

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Formatting in Logbook

>>> from logbook import StderrHandler
>>> handler = StderrHandler (
...
format_string = ’{ record . channel }: { record . message } ’)
>>> handler . formatter
< logbook . handlers . St ri n gF or ma t te r object at 0 x100641b90 >

The end
Why use logging

Basics

When to use what?

Logbook

Custom formatters

>>> def my_formatter ( record , handler ):
... return record . message
...
>>> handler . formatter = my_formatter

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Custom formatters

>>> def my_formatter ( record , handler ):
... return record . message
...
>>> handler . formatter = my_formatter

Tip:
Or use Jinja!

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

The end

Extra fields

handler = StderrHandler ( format_string =
’{ record . channel }: { record . message ) [{ record . extra [ cwd ]}] ’)
Why use logging

Basics

When to use what?

Logbook

Redis

import logbook
from logbook . queues import RedisHandler
handler = RedisHandler ()
l = logbook . Logger ()
with handler :
l . info ( ’ Your log message ’)

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

RabbitMQ

Handler
handler = R a bb it MQ H an dl er ( ’ amqp :// guest : gu e st @l oc a lh os t // ’ ,
queue = ’ my_log ’)

Subscriber
with target_h andler :
subscriber = R a b b i t M Q S u b s c r i b e r (
’ amqp :// guest : gu e st @l oc a lh os t // ’ , queue = ’ my_log ’)
subscriber . d i s p a t ch _ f o r e v e r ()

The end
Why use logging

Basics

When to use what?

Logbook

ZeroMQ

Don’t use it. (It’s broken)

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

The end

Minimize logging

>>> from logbook import FingersCrossedHandler , StderrHandler
>>> handler = F i n g e r s C r o s s e d H a n d l e r ( StderrHandler ())
>>> with handler . a p p l i c a t i o n b o u n d ():
...
logbook . info ( ’ Hello ’)
...
...
>>> handler = F i n g e r s C r o s s e d H a n d l e r ( StderrHandler ())
>>> with handler . a p p l i c a t i o n b o u n d ():
...
logbook . info ( ’ Hello ’)
...
logbook . error ( ’ Bye ’)
...
...
[2013 -12 -16 11:12] INFO : Generic : Hello
[2013 -12 -16 11:12] ERROR : Generic : Bye
Why use logging

Basics

When to use what?

Logbook

Error reporting

TestHandler

>>> from logbook import TestHandler , Logger
>>> logger = Logger ( ’ Testing ’)
>>> handler = TestHandler ()
>>> handler . push_thread ()
>>> logger . warn ( ’ Hello World ’)
>>> handler . records
[ < logbook . base . LogRecord object at 0 x100640cd0 >]
>>> handler . f o r m a t t e d _ r e c o r d s
[ u ’[ WARNING ] Testing : Hello World ’]

The end
Why use logging

Basics

When to use what?

Logbook

Github

github.com/mitsuhiko/logbook

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Emails?

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

The end

Airbrake

Airbrake is the leading exception reporting service, currently
providing error tracking for 50,000 applications with support for 18
programming languages.
Why use logging

Basics

When to use what?

Logbook

Sign up

airbrake.io

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Flask
from flask import Flask , request
from airbrake import A i r b r a k e E r r o r H a n d l e r
import gevent
@app . errorhandler (500)
def interna l_error ( error ):
if app . config [ ’ E X C E P T I O N _ L O G G I N G ’ ]:
handler = A i r b r a k e E r r o r H a n d l e r (
api_key = app . config [ ’ A I R B R E A K _ A P I _ K E Y ’] ,
env_name = ENV , request_url = request . url ,
request_path = request . path ,
requ est_meth od = request . method ,
request_args = request . args ,
r eq ue st _ he ad er s = request . headers )
gevent . spawn ( handler . emit , error )

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Django

AIRBRAKE = {
’ API_KEY ’: ’ y o u r _ a p i _ k e y _ h e r e ’ ,
’ USE_SSL ’: True ,
’ TIMEOUT ’: 5 ,
’ ENVIRONMENT ’: ’ u n i q u e _ n a m e _ f o r _ e n v i r o n m e n t ’ ,
}

The end
Why use logging

Basics

When to use what?

Logbook

Errbit

github.com/errbit/errbit

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

The end

Sentry
getsentry.com

Sentry is a realtime event logging and aggregation platform. At its
core it specializes in monitoring errors and extracting all the
information needed to do a proper post-mortem without any of the
hassle of the standard user feedback loop.
Why use logging

Basics

When to use what?

Detail

Logbook

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

More detail

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Install the server

sentry.readthedocs.org

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Sentry + Logbook
raven.readthedocs.org/en/latest/config/logbook.html

Install raven
pip install raven

Your app code will have this at the entry point
from raven . handlers . logbook import SentryHandler
client = Client (...)
sent ry_handl er = SentryHandler ( client )
with sentry_h andler . a p pl i c a t i o n b o u n d ():
# e v e r y t h i n g logged here will go to sentry .
...

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

Pay attention to formatting!
Sentry will intelligently group messages if you use proper string formatting.

logger . error ( ’ There was some {} error ’ , ’ crazy ’)
logger . error ( ’ There was some {} error ’ , ’ fun ’)
logger . error ( ’ There was some {} error ’ , 1)

The end
Why use logging

Basics

When to use what?

Logbook

Tagging
logger . error ( ’ Could not do that ’ ,
tags ={ ’ user email ’: ’ foo@bar ’ })

Error reporting

The end
Why use logging

Basics

When to use what?

Logbook

Error reporting

The end

TicketingHandler
Create unique tickets for log records and keep track of the number of times these log
records were created

from logbook import ERROR
from logbook . ticketing import T i c k e t i n g H a n d l e r
handler = T i c k e t i n g Ha n d l e r ( ’ postgres :// localhost / database ’ ,
level = ERROR )
with handler :
# e v e r y t h i n g in this block and thread will be handled by
# the t i c k e t i n g d a t a b a s e handler
...
Why use logging

Basics

When to use what?

Logbook

Error reporting

Phew! It’s finally over!

Reach me at fayaz at dexetra dot com.

The end

More Related Content

What's hot

Ida python intro
Ida python introIda python intro
Ida python intro小静 安
 
Découvrir dtrace en ligne de commande.
Découvrir dtrace en ligne de commande.Découvrir dtrace en ligne de commande.
Découvrir dtrace en ligne de commande.CocoaHeads France
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1Albert Rosa
 
CodeIgniter Ant Scripting
CodeIgniter Ant ScriptingCodeIgniter Ant Scripting
CodeIgniter Ant ScriptingAlbert Rosa
 
Flask With Server-Sent Event
Flask With Server-Sent EventFlask With Server-Sent Event
Flask With Server-Sent EventTencent
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testingVisual Engineering
 
YAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEYAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEThiago Rondon
 
How Functions Work
How Functions WorkHow Functions Work
How Functions WorkSaumil Shah
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistAnton Arhipov
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlHideaki Ohno
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistAnton Arhipov
 
Turbo charge your logs
Turbo charge your logsTurbo charge your logs
Turbo charge your logsJeremy Cook
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Assurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkGosuke Miyashita
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytestSuraj Deshmukh
 
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsAjin Abraham
 

What's hot (20)

Ida python intro
Ida python introIda python intro
Ida python intro
 
Découvrir dtrace en ligne de commande.
Découvrir dtrace en ligne de commande.Découvrir dtrace en ligne de commande.
Découvrir dtrace en ligne de commande.
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1
 
CodeIgniter Ant Scripting
CodeIgniter Ant ScriptingCodeIgniter Ant Scripting
CodeIgniter Ant Scripting
 
Flask With Server-Sent Event
Flask With Server-Sent EventFlask With Server-Sent Event
Flask With Server-Sent Event
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 
Anyevent
AnyeventAnyevent
Anyevent
 
YAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEYAPC::Brasil 2009, POE
YAPC::Brasil 2009, POE
 
How Functions Work
How Functions WorkHow Functions Work
How Functions Work
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With Javassist
 
Turbo charge your logs
Turbo charge your logsTurbo charge your logs
Turbo charge your logs
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
node ffi
node ffinode ffi
node ffi
 
Assurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring framework
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
 

Viewers also liked

FLTK Summer Course - Part II - Second Impact - Exercises
FLTK Summer Course - Part II - Second Impact - Exercises FLTK Summer Course - Part II - Second Impact - Exercises
FLTK Summer Course - Part II - Second Impact - Exercises Michel Alves
 
FLTK Summer Course - Part VIII - Eighth Impact
FLTK Summer Course - Part VIII - Eighth ImpactFLTK Summer Course - Part VIII - Eighth Impact
FLTK Summer Course - Part VIII - Eighth ImpactMichel Alves
 
Manipulating file in Python
Manipulating file in PythonManipulating file in Python
Manipulating file in Pythonshoukatali500
 
Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)Peter Kofler
 
FLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - ExercisesFLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - ExercisesMichel Alves
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsCarl Brown
 
TMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and ReportsTMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and ReportsMichel Alves
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...Alessandro Molina
 
FLTK Summer Course - Part VII - Seventh Impact
FLTK Summer Course - Part VII  - Seventh ImpactFLTK Summer Course - Part VII  - Seventh Impact
FLTK Summer Course - Part VII - Seventh ImpactMichel Alves
 
FLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second ImpactFLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second ImpactMichel Alves
 
FLTK Summer Course - Part III - Third Impact
FLTK Summer Course - Part III - Third ImpactFLTK Summer Course - Part III - Third Impact
FLTK Summer Course - Part III - Third ImpactMichel Alves
 
Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2Anil Sagar
 
FLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesFLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesMichel Alves
 
Using Git on the Command Line
Using Git on the Command LineUsing Git on the Command Line
Using Git on the Command LineBrian Richards
 
Git hooks For PHP Developers
Git hooks For PHP DevelopersGit hooks For PHP Developers
Git hooks For PHP DevelopersUmut IŞIK
 
Creating Custom Drupal Modules
Creating Custom Drupal ModulesCreating Custom Drupal Modules
Creating Custom Drupal Modulestanoshimi
 
Servicios web con Python
Servicios web con PythonServicios web con Python
Servicios web con PythonManuel Pérez
 
"Git Hooked!" Using Git hooks to improve your software development process
"Git Hooked!" Using Git hooks to improve your software development process"Git Hooked!" Using Git hooks to improve your software development process
"Git Hooked!" Using Git hooks to improve your software development processPolished Geek LLC
 

Viewers also liked (20)

asyncio internals
asyncio internalsasyncio internals
asyncio internals
 
FLTK Summer Course - Part II - Second Impact - Exercises
FLTK Summer Course - Part II - Second Impact - Exercises FLTK Summer Course - Part II - Second Impact - Exercises
FLTK Summer Course - Part II - Second Impact - Exercises
 
FLTK Summer Course - Part VIII - Eighth Impact
FLTK Summer Course - Part VIII - Eighth ImpactFLTK Summer Course - Part VIII - Eighth Impact
FLTK Summer Course - Part VIII - Eighth Impact
 
Manipulating file in Python
Manipulating file in PythonManipulating file in Python
Manipulating file in Python
 
Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)
 
FLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - ExercisesFLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - Exercises
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
 
TMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and ReportsTMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and Reports
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
 
FLTK Summer Course - Part VII - Seventh Impact
FLTK Summer Course - Part VII  - Seventh ImpactFLTK Summer Course - Part VII  - Seventh Impact
FLTK Summer Course - Part VII - Seventh Impact
 
FLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second ImpactFLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second Impact
 
FLTK Summer Course - Part III - Third Impact
FLTK Summer Course - Part III - Third ImpactFLTK Summer Course - Part III - Third Impact
FLTK Summer Course - Part III - Third Impact
 
Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2
 
FLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesFLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - Exercises
 
Using Git on the Command Line
Using Git on the Command LineUsing Git on the Command Line
Using Git on the Command Line
 
Git hooks For PHP Developers
Git hooks For PHP DevelopersGit hooks For PHP Developers
Git hooks For PHP Developers
 
Creating Custom Drupal Modules
Creating Custom Drupal ModulesCreating Custom Drupal Modules
Creating Custom Drupal Modules
 
Servicios web con Python
Servicios web con PythonServicios web con Python
Servicios web con Python
 
"Git Hooked!" Using Git hooks to improve your software development process
"Git Hooked!" Using Git hooks to improve your software development process"Git Hooked!" Using Git hooks to improve your software development process
"Git Hooked!" Using Git hooks to improve your software development process
 

Similar to Logging in Python for large applications

Low Latency Logging with RabbitMQ (Brno PHP, CZ - 20th Sep 2014)
Low Latency Logging with RabbitMQ (Brno PHP, CZ - 20th Sep 2014)Low Latency Logging with RabbitMQ (Brno PHP, CZ - 20th Sep 2014)
Low Latency Logging with RabbitMQ (Brno PHP, CZ - 20th Sep 2014)James Titcumb
 
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)James Titcumb
 
Getting modern with logging via log4perl
Getting modern with logging via log4perlGetting modern with logging via log4perl
Getting modern with logging via log4perlDean Hamstead
 
Logging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqLogging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqDoruk Uluçay
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4Jjkumaranc
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4Jjkumaranc
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4Jjkumaranc
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4Jjkumaranc
 
Django best practices for logging and signals
Django best practices for logging and signals Django best practices for logging and signals
Django best practices for logging and signals flywindy
 
Log4cpp - Updated - to verify modify updates
Log4cpp - Updated - to verify modify updatesLog4cpp - Updated - to verify modify updates
Log4cpp - Updated - to verify modify updatesyosaggregator2
 
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
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 
Post-Mortem Debugging and Web Development
Post-Mortem Debugging and Web DevelopmentPost-Mortem Debugging and Web Development
Post-Mortem Debugging and Web DevelopmentAlessandro Molina
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingAlessandro Molina
 
Low latency Logging (BrightonPHP - 18th Nov 2013)
Low latency Logging (BrightonPHP - 18th Nov 2013)Low latency Logging (BrightonPHP - 18th Nov 2013)
Low latency Logging (BrightonPHP - 18th Nov 2013)James Titcumb
 
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)Pixie Labs
 
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)Zain Asgar
 

Similar to Logging in Python for large applications (20)

Low Latency Logging with RabbitMQ (Brno PHP, CZ - 20th Sep 2014)
Low Latency Logging with RabbitMQ (Brno PHP, CZ - 20th Sep 2014)Low Latency Logging with RabbitMQ (Brno PHP, CZ - 20th Sep 2014)
Low Latency Logging with RabbitMQ (Brno PHP, CZ - 20th Sep 2014)
 
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)
 
Getting modern with logging via log4perl
Getting modern with logging via log4perlGetting modern with logging via log4perl
Getting modern with logging via log4perl
 
Logging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqLogging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, Seq
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4J
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4J
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4J
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4J
 
Django best practices for logging and signals
Django best practices for logging and signals Django best practices for logging and signals
Django best practices for logging and signals
 
log4cpp-29/10
log4cpp-29/10log4cpp-29/10
log4cpp-29/10
 
Log4cpp - Updated - to verify modify updates
Log4cpp - Updated - to verify modify updatesLog4cpp - Updated - to verify modify updates
Log4cpp - Updated - to verify modify updates
 
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
 
Logging
LoggingLogging
Logging
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
Post-Mortem Debugging and Web Development
Post-Mortem Debugging and Web DevelopmentPost-Mortem Debugging and Web Development
Post-Mortem Debugging and Web Development
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
Low latency Logging (BrightonPHP - 18th Nov 2013)
Low latency Logging (BrightonPHP - 18th Nov 2013)Low latency Logging (BrightonPHP - 18th Nov 2013)
Low latency Logging (BrightonPHP - 18th Nov 2013)
 
Log4j in 8 slides
Log4j in 8 slidesLog4j in 8 slides
Log4j in 8 slides
 
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
 
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Logging in Python for large applications

  • 1. Why use logging Basics When to use what? Logbook Logging in Python For complex applications Fayaz Yusuf Khan 20 December 2013 Error reporting The end
  • 2. Why use logging Basics When to use what? Logbook Why use logging? Error reporting The end
  • 3. Why use logging Basics When to use what? Logbook Why use logging? • All errors happen in runtime. Error reporting The end
  • 4. Why use logging Basics When to use what? Logbook Why use logging? • All errors happen in runtime. • Testing can never be 100% Error reporting The end
  • 5. Why use logging Basics When to use what? Logbook Error reporting import logging logging . warning ( ’ Watch out ! ’) # will print a message logging . info ( ’I told you so ’) # will not print a n y t h i n g The end
  • 6. Why use logging Basics When to use what? Logbook Error reporting import logging logging . warning ( ’ Watch out ! ’) # will print a message logging . info ( ’I told you so ’) # will not print a n y t h i n g Output: WARNING:root:Watch out! The end
  • 7. Why use logging Basics When to use what? Logbook Error reporting Logging to a file import logging logging . basicConfig ( filename = ’ example . log ’ , level = logging . DEBUG ) logging . debug ( ’ This message should go to the log file ’) logging . info ( ’ So should this ’) logging . warning ( ’ And this , too ’) The end
  • 8. Why use logging Basics When to use what? Logbook Error reporting Logging to a file import logging logging . basicConfig ( filename = ’ example . log ’ , level = logging . DEBUG ) logging . debug ( ’ This message should go to the log file ’) logging . info ( ’ So should this ’) logging . warning ( ’ And this , too ’) Output: DEBUG:root:This message should go to the log file INFO:root:So should this WARNING:root:And this, too The end
  • 9. Why use logging Basics When to use what? Logbook Initializing logger = logging . getLogger ( __name__ ) Error reporting The end
  • 10. Why use logging Basics When to use what? Logbook Error reporting The end print() Display console output for ordinary usage of a command line script or program
  • 11. Why use logging Basics When to use what? Logbook Error reporting logging.info() Report events that occur during normal operation of a program (e.g. for status monitoring or fault investigation) The end
  • 12. Why use logging Basics When to use what? Logbook Error reporting logging.debug() Very detailed output for diagnostic purposes The end
  • 13. Why use logging Basics When to use what? Logbook Error reporting warnings.warn() In library code if the issue is avoidable and the client application should be modified to eliminate the warning. The end
  • 14. Why use logging Basics When to use what? Logbook Error reporting logging.warning() If there is nothing the client application can do about the situation, but the event should still be noted The end
  • 15. Why use logging Basics When to use what? Logbook Error reporting Report an error regarding a particular runtime event The end
  • 16. Why use logging Basics When to use what? Logbook Error reporting Raise an exception Report an error regarding a particular runtime event The end
  • 17. Why use logging Basics When to use what? Logbook Error reporting logging.error() or logging.exception() Report suppression of an error without raising an exception (e.g. error handler in a long-running server process) The end
  • 18. Why use logging Basics When to use what? Logbook Error reporting The end logging.critical() A serious error, indicating that the program itself may be unable to continue running.
  • 19. Why use logging Basics When to use what? Logbook Error reporting Logbook pythonhosted.org/Logbook Logbook is a logging sytem for Python that replaces the standard library’s logging module. The end
  • 20. Why use logging Basics When to use what? Logbook Error reporting >>> from logbook import Logger >>> log = Logger ( ’ Logbook ’) >>> log . info ( ’ Hello , World ! ’) [2010 -07 -23 16:34] INFO : Logbook : Hello , World ! The end
  • 21. Why use logging Basics When to use what? Logbook Error reporting Context managers everywhere! from logbook import SyslogHandler error_handler = SyslogHandler ( ’ logbook example ’ , level = ’ ERROR ’) with error_handler . a p p l i c a t i o n b o u n d (): # wh a t e v e r is e x e c u t e d here and an error is logged to # the error handler ... The end
  • 22. Why use logging Basics When to use what? Logbook Error reporting Getting your libraries and old code to behave from logbook . compat import r e d i r ec t _ l o g g i n g r e d i r e ct _ l o g g i n g () The end
  • 23. Why use logging Basics When to use what? Logbook Error reporting Injecting context import os from logbook import Processor def inject_cwd ( record ): record . extra [ ’ cwd ’] = os . getcwd () with my_handler . a p p l i c at i o n b o u n d (): with Processor ( inject_cwd ). a p p l i c a t i o n b o u n d (): # e v e r y t h i n g logged here will have the current # working d i r e c t o r y in the log record . ... The end
  • 24. Why use logging Basics When to use what? Logbook Error reporting Formatting in Logging import logging logging . basicConfig ( format = ’ %( levelname ) s :%( message ) s ’ , level = logging . DEBUG ) The end
  • 25. Why use logging Basics When to use what? Logbook Error reporting Formatting in Logbook >>> from logbook import StderrHandler >>> handler = StderrHandler ( ... format_string = ’{ record . channel }: { record . message } ’) >>> handler . formatter < logbook . handlers . St ri n gF or ma t te r object at 0 x100641b90 > The end
  • 26. Why use logging Basics When to use what? Logbook Custom formatters >>> def my_formatter ( record , handler ): ... return record . message ... >>> handler . formatter = my_formatter Error reporting The end
  • 27. Why use logging Basics When to use what? Logbook Custom formatters >>> def my_formatter ( record , handler ): ... return record . message ... >>> handler . formatter = my_formatter Tip: Or use Jinja! Error reporting The end
  • 28. Why use logging Basics When to use what? Logbook Error reporting The end Extra fields handler = StderrHandler ( format_string = ’{ record . channel }: { record . message ) [{ record . extra [ cwd ]}] ’)
  • 29. Why use logging Basics When to use what? Logbook Redis import logbook from logbook . queues import RedisHandler handler = RedisHandler () l = logbook . Logger () with handler : l . info ( ’ Your log message ’) Error reporting The end
  • 30. Why use logging Basics When to use what? Logbook Error reporting RabbitMQ Handler handler = R a bb it MQ H an dl er ( ’ amqp :// guest : gu e st @l oc a lh os t // ’ , queue = ’ my_log ’) Subscriber with target_h andler : subscriber = R a b b i t M Q S u b s c r i b e r ( ’ amqp :// guest : gu e st @l oc a lh os t // ’ , queue = ’ my_log ’) subscriber . d i s p a t ch _ f o r e v e r () The end
  • 31. Why use logging Basics When to use what? Logbook ZeroMQ Don’t use it. (It’s broken) Error reporting The end
  • 32. Why use logging Basics When to use what? Logbook Error reporting The end Minimize logging >>> from logbook import FingersCrossedHandler , StderrHandler >>> handler = F i n g e r s C r o s s e d H a n d l e r ( StderrHandler ()) >>> with handler . a p p l i c a t i o n b o u n d (): ... logbook . info ( ’ Hello ’) ... ... >>> handler = F i n g e r s C r o s s e d H a n d l e r ( StderrHandler ()) >>> with handler . a p p l i c a t i o n b o u n d (): ... logbook . info ( ’ Hello ’) ... logbook . error ( ’ Bye ’) ... ... [2013 -12 -16 11:12] INFO : Generic : Hello [2013 -12 -16 11:12] ERROR : Generic : Bye
  • 33. Why use logging Basics When to use what? Logbook Error reporting TestHandler >>> from logbook import TestHandler , Logger >>> logger = Logger ( ’ Testing ’) >>> handler = TestHandler () >>> handler . push_thread () >>> logger . warn ( ’ Hello World ’) >>> handler . records [ < logbook . base . LogRecord object at 0 x100640cd0 >] >>> handler . f o r m a t t e d _ r e c o r d s [ u ’[ WARNING ] Testing : Hello World ’] The end
  • 34. Why use logging Basics When to use what? Logbook Github github.com/mitsuhiko/logbook Error reporting The end
  • 35. Why use logging Basics When to use what? Logbook Error reporting Error reporting The end
  • 36. Why use logging Basics When to use what? Logbook Error reporting Emails? Error reporting The end
  • 37. Why use logging Basics When to use what? Logbook Error reporting Error reporting The end
  • 38. Why use logging Basics When to use what? Logbook Error reporting The end Airbrake Airbrake is the leading exception reporting service, currently providing error tracking for 50,000 applications with support for 18 programming languages.
  • 39. Why use logging Basics When to use what? Logbook Sign up airbrake.io Error reporting The end
  • 40. Why use logging Basics When to use what? Logbook Error reporting Flask from flask import Flask , request from airbrake import A i r b r a k e E r r o r H a n d l e r import gevent @app . errorhandler (500) def interna l_error ( error ): if app . config [ ’ E X C E P T I O N _ L O G G I N G ’ ]: handler = A i r b r a k e E r r o r H a n d l e r ( api_key = app . config [ ’ A I R B R E A K _ A P I _ K E Y ’] , env_name = ENV , request_url = request . url , request_path = request . path , requ est_meth od = request . method , request_args = request . args , r eq ue st _ he ad er s = request . headers ) gevent . spawn ( handler . emit , error ) The end
  • 41. Why use logging Basics When to use what? Logbook Error reporting Django AIRBRAKE = { ’ API_KEY ’: ’ y o u r _ a p i _ k e y _ h e r e ’ , ’ USE_SSL ’: True , ’ TIMEOUT ’: 5 , ’ ENVIRONMENT ’: ’ u n i q u e _ n a m e _ f o r _ e n v i r o n m e n t ’ , } The end
  • 42. Why use logging Basics When to use what? Logbook Errbit github.com/errbit/errbit Error reporting The end
  • 43. Why use logging Basics When to use what? Logbook Error reporting The end Sentry getsentry.com Sentry is a realtime event logging and aggregation platform. At its core it specializes in monitoring errors and extracting all the information needed to do a proper post-mortem without any of the hassle of the standard user feedback loop.
  • 44. Why use logging Basics When to use what? Detail Logbook Error reporting The end
  • 45. Why use logging Basics When to use what? Logbook More detail Error reporting The end
  • 46. Why use logging Basics When to use what? Logbook Install the server sentry.readthedocs.org Error reporting The end
  • 47. Why use logging Basics When to use what? Logbook Error reporting Sentry + Logbook raven.readthedocs.org/en/latest/config/logbook.html Install raven pip install raven Your app code will have this at the entry point from raven . handlers . logbook import SentryHandler client = Client (...) sent ry_handl er = SentryHandler ( client ) with sentry_h andler . a p pl i c a t i o n b o u n d (): # e v e r y t h i n g logged here will go to sentry . ... The end
  • 48. Why use logging Basics When to use what? Logbook Error reporting Pay attention to formatting! Sentry will intelligently group messages if you use proper string formatting. logger . error ( ’ There was some {} error ’ , ’ crazy ’) logger . error ( ’ There was some {} error ’ , ’ fun ’) logger . error ( ’ There was some {} error ’ , 1) The end
  • 49. Why use logging Basics When to use what? Logbook Tagging logger . error ( ’ Could not do that ’ , tags ={ ’ user email ’: ’ foo@bar ’ }) Error reporting The end
  • 50. Why use logging Basics When to use what? Logbook Error reporting The end TicketingHandler Create unique tickets for log records and keep track of the number of times these log records were created from logbook import ERROR from logbook . ticketing import T i c k e t i n g H a n d l e r handler = T i c k e t i n g Ha n d l e r ( ’ postgres :// localhost / database ’ , level = ERROR ) with handler : # e v e r y t h i n g in this block and thread will be handled by # the t i c k e t i n g d a t a b a s e handler ...
  • 51. Why use logging Basics When to use what? Logbook Error reporting Phew! It’s finally over! Reach me at fayaz at dexetra dot com. The end