Are logs a software engineer’s best friend? Yes — follow these best practices

A presentation at Laracon AU in October 2019 in Sydney NSW, Australia by Geshan Manandhar

Slide 1

Slide 1

Are logs a software engineer’s best friend? Yes — follow these best practices Geshan Manandhar Senior Software Engineer (THE ICONIC) @geshan

Slide 2

Slide 2

whoami ◉ Senior Software Engineer ○ Tech solution provider ◉ Agile follower ◉ Conditional microservices believer

Slide 3

Slide 3

I am from Kathmandu, Nepal

Slide 4

Slide 4

I work at THE ICONIC

Slide 5

Slide 5

Agenda ◉ ◉ ◉ ◉ ◉ ◉ What is application log? Why log from the application level Tools of the trade — How? Logging Best practices Key Takeaways Demo

Slide 6

Slide 6

What is application log?

Slide 7

Slide 7

“Logs are the stream of aggregated, time-ordered events collected from the output streams of all running processes and backing services.” - 12Factor.net “ Source: https://www.12factor.net/logs

Slide 8

Slide 8

“An application log is a file of events that are logged by a software application. It contains errors, informational events and warnings.” - Technopedia “ Source: https://www.techopedia.com/definition/1819/application-log

Slide 9

Slide 9

Application logs are like having the right reading glasses

Slide 10

Slide 10

Why log from application level?

Slide 11

Slide 11

“The feature I deployed to production last week was working fine till yesterday, but now I have no idea why it is not working!” - One of us “

Slide 12

Slide 12

Logs help to pinpoint the exact place where the software is not working as expected

Slide 13

Slide 13

To stop speculating and figure out the real data and metrics on any env

Slide 14

Slide 14

Logs are one of the ways your app communicates back to you

Slide 15

Slide 15

Even if you land into a mess, you know a way to sort things fast (MTTR)

Slide 16

Slide 16

Having proper logs is like having a torch in a dark place

Slide 17

Slide 17

Tools of the trade — How?

Slide 18

Slide 18

Please don’t hammer the screw :)

Slide 19

Slide 19

Simplified components of logging Application generates logs Local File / Stdout Logs are ingested Using a library or over https Software that parses, analyzes and shows logs Logs are shipped/ingested with an agent or log shipper Software Engineer views/searches logs

Slide 20

Slide 20

Use a trusted logging library Language Library Github stars PHP Monolog ~16.0k TypeScript/JS Winston ~14.2k Native N/A Python Note: Don’t forget about monolog handlers and formatters :)

Slide 21

Slide 21

Use a trustworthy software to view and search your logs Self Hosted SAAS Cloud Provider Based

Slide 22

Slide 22

No tail -f …, a good UI to view/search logs will make your life a lot easier

Slide 23

Slide 23

Logging best practices

Slide 24

Slide 24

Log information optimally Too Much = noise, too less = inadequate information

Slide 25

Slide 25

RFC-5425 (8 Levels) Emergency Alert Critical Error Warning Notice Info Debug Always follow logs severity standards Emergency = phone rings at 1 AM, Info = good to know

Slide 26

Slide 26

Structure your logs Structured logs are easier to parse and search, always provide context.

Slide 27

Slide 27

Don’t hamper speed and performance Write logs locally or async as far as possible, may be use a queue and consumer.

Slide 28

Slide 28

Add traceability for microservices Same request ID travels across services. Ability for distributed tracing.

Slide 29

Slide 29

Do not log sensitive information Like passwords, credit card information, phone numbers etc

Slide 30

Slide 30

Key Takeaways

Slide 31

Slide 31

Start logging today

Slide 32

Slide 32

It is easier than you think and benefits outweigh the cost

Slide 33

Slide 33

Logs can reveal things you didn’t know existed at unexpected sources

Slide 34

Slide 34

Logging > error tracking, it keeps a track of your application health

Slide 35

Slide 35

Find the right tools, invest in a log management software that suits your needs

Slide 36

Slide 36

Logs with optimally configured alerts are very powerful

Slide 37

Slide 37

Demo ● https://github.com/geshan/laravel6-logging ● Pull Request - PR

Slide 38

Slide 38

Logs are an integral part of building happy, robust and scalable software

Slide 39

Slide 39

Thanks! Any questions? Later :) THE ICONIC is hiring - Engineering Manager You can find me at ◉ ◉ ◉ @geshan (geshan@gmail.com) Geshan.com.np Slides: bit.ly/logging-lau Presentation template by SlidesCarnival

Slide 40

Slide 40

Credits/References ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ ◉ https://pixabay.com/en/primate-ape-thinking-mimic-view-1019101/ https://pixabay.com/photos/batch-dry-firewood-forestry-logs-1868104/ https://www.techopedia.com/definition/1819/application-log https://www.scalyr.com/blog/application-logging-practices-adopt/ https://unsplash.com/photos/4Bs9kSDJsdc https://unsplash.com/photos/FtZL0r4DZYk https://pixabay.com/photos/calm-water-clear-drink-glass-2315559/ https://pixabay.com/photos/backdrop-block-brick-building-21534/ https://www.afcent.af.mil/News/Art/igphoto/2000289219/ https://unsplash.com/photos/MS0q8GqjVrY https://pixabay.com/photos/tools-work-repair-hammer-2145770/ https://pixabay.com/photos/needle-in-a-haystack-needle-haystack-1752846/ https://pixabay.com/photos/building-zen-man-boy-pyramid-game-2665812/ https://unsplash.com/photos/0vsk2_9dkqo https://unsplash.com/photos/pUT2Ujm6FP4 https://unsplash.com/photos/ZaGcU6BxJEc https://peter.bourgon.org/blog/2016/02/07/logging-v-instrumentation.html https://www.loggly.com/blog/30-best-practices-logging-scale/ https://geshan.com.np/blog/2015/08/importance-of-logging-in-your-applications/ https://www.scalyr.com/media-gallery-4/ https://aws.amazon.com/blogs/developer/php-application-logging-with-amazon-cloudwatch-logs-and-monolog/ https://raygun.com/blog/what-is-mttr/ https://pixabay.com/photos/pc-computer-stethoscope-technology-3540378/ https://krebsonsecurity.com/2019/03/facebook-stored-hundreds-of-millions-of-user-passwords-in-plain-text-for-years/