Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez javiergs@calpoly.edu www.javiergs.info o ffi ce: 14 -227 CSC 307 Introduction to Software Engineering Lecture 10. Logging Process

Slide 2

Slide 2 text

Problem 9

Slide 3

Slide 3 text

Problem 10

Slide 4

Slide 4 text

Bad Idea System.out.println 11 Messages

Slide 5

Slide 5 text

Logging • Recording events, a ctions, or mess a ges th a t occur during the execution of a progr a m. • Proper logging is essenti a l for m a int a ining a nd troubleshooting a pplic a tions e ff ectively throughout their lifecycle. 12

Slide 6

Slide 6 text

Good Idea 13 message 01 message 02 message 03 message 04 message 05

Slide 7

Slide 7 text

SLF4J Logback • St a nds for Simple Logging F a c a de for J a v a • It provides a uni f ied interf a ce for logging oper a tions, a llowing developers to write logging code without binding their a pplic a tion to a speci f ic logging implement a tion. • We need to t a lk a bout the F a c a de P a ttern 14

Slide 8

Slide 8 text

Getting Started

Slide 9

Slide 9 text

SLF4J Logback | Add the dependency 16 https://github.com/CSC3100/Tool-Logging

Slide 10

Slide 10 text

SLF4J Logback | Logging 17 https://github.com/CSC3100/Tool-Logging

Slide 11

Slide 11 text

SLF4J Logback | Logging 18 https://github.com/CSC3100/Tool-Logging

Slide 12

Slide 12 text

Severity Level 19 TRACE DEBUG INFO WARN ERROR Severity

Slide 13

Slide 13 text

We want this 20 message 01 message 02 message 03 message 04 message 05 trace() debug() info () warn () error() Logger 20

Slide 14

Slide 14 text

Maven File and Directories 21

Slide 15

Slide 15 text

Resources Folder • The resources folder in a M a ven project stores non-source-code f iles th a t your a pplic a tion needs, such a s con f igur a tion f iles, property f iles, im a ges, a nd other resources. • These f iles a re included in the f in a l build output a nd a v a il a ble on the cl a ssp a th a t runtime. 22

Slide 16

Slide 16 text

src/main/resources/logback.xml • logb a ck.xml is a con f igur a tion f ile for SLF4J Logb a ck. • It de f ines how logging should be h a ndled, including log levels, a ppenders (where logs a re written), a nd log form a ts. • When your a pplic a tion st a rts, SLF4J Logb a ck a utom a tic a lly looks for this con f igur a tion f ile. 23

Slide 17

Slide 17 text

ConsoleAppender 24 message 01 message 02 message 03 message 04 message 05 trace() debug() info () warn () error() Logger 24 Appender

Slide 18

Slide 18 text

src/main/resources/logback.xml 25 https://github.com/CSC3100/Tool-Logging

Slide 19

Slide 19 text

SLF4J Logback | Logging 26

Slide 20

Slide 20 text

ConsoleAppender 27 message 01 message 02 message 03 message 04 message 05 trace() debug() info () warn () error() Logger 27 Appender

Slide 21

Slide 21 text

Encoder

Slide 22

Slide 22 text

Logstash Logback Encoder | POM.xml • Let’s use a nother libr a ry to t a ke a dv a nt a ge of extr a encoders • form a t Spring Boot logs in JSON form a t 29 https://github.com/CSC3100/Tool-Logging

Slide 23

Slide 23 text

src/main/resources/logback.xml 30 https://github.com/CSC3100/Tool-Logging

Slide 24

Slide 24 text

SLF4J Logback | Logging 31

Slide 25

Slide 25 text

FileAppender

Slide 26

Slide 26 text

Next 33 trace() debug() info () warn () error() message 01 message 02 message 03 message 04 message 05 Logger Appender Appender

Slide 27

Slide 27 text

src/main/resources/logback.xml 34 https://github.com/CSC3100/Tool-Logging

Slide 28

Slide 28 text

SLF4J Logback | Logging 35

Slide 29

Slide 29 text

Cloud-Based Log Management

Slide 30

Slide 30 text

Next 37 trace() debug() info () warn () error() message 01 message 02 message 03 message 04 message 05 Logger Appender

Slide 31

Slide 31 text

Cloud-Base Log Management • Cloud-b a sed log m a n a gement refers to the pr a ctice of collecting, storing, a n a lyzing, a nd m a n a ging log d a t a using cloud services. • This a ppro a ch lever a ges cloud computing to h a ndle the v a st a mounts of log d a t a 38

Slide 32

Slide 32 text

betterstack.com/logs 39

Slide 33

Slide 33 text

We need keys 40 String key = "XYZabc123259#$%#$Fcaskjhdux_2342445Calp";

Slide 34

Slide 34 text

betterstack.com/logs 41

Slide 35

Slide 35 text

betterstack.com/logs 42 WE6x9ya1dfMwRTouP9DEBmg

Slide 36

Slide 36 text

HttpAppender Our very own creation Just for fun

Slide 37

Slide 37 text

SLF4J Logback | Add the dependency 44 Just for JSON Support https://github.com/CSC3100/Tool-Logging

Slide 38

Slide 38 text

src/main/resources/logback.xml 45 WE6x9ya1dfMwRTouP9DEB https://github.com/CSC3100/Tool-Logging

Slide 39

Slide 39 text

javiergs.HttpAppender (Part 1/4) 46 https://github.com/CSC3100/Tool-Logging

Slide 40

Slide 40 text

javiergs.HttpAppender (Part 2/4) 47 https://github.com/CSC3100/Tool-Logging

Slide 41

Slide 41 text

javiergs.HttpAppender (Part 3/4) 48 https://github.com/CSC3100/Tool-Logging

Slide 42

Slide 42 text

javiergs.HttpAppender (Part 4/4) 49 https://github.com/CSC3100/Tool-Logging

Slide 43

Slide 43 text

logs.betterstack.com 50

Slide 44

Slide 44 text

Full Solution 51 trace() debug() info () warn () error() message 01 message 02 message 03 message 04 message 05 Logger Appender Appender Appender

Slide 45

Slide 45 text

Questions 52

Slide 46

Slide 46 text

CSC 307 Introduction to Software Engineering Javier Gonzalez-Sanchez, Ph.D. javiergs@calpoly.edu Summer 2024 Copyright. These slides can only be used as study material for the class CSC307 at Cal Poly. They cannot be distributed or used for another purpose.