Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227 CSC 305 Individual Software Design and Development Lecture 05. Logging

Slide 2

Slide 2 text

Previously

Slide 3

Slide 3 text

Maven File and Directories 3

Slide 4

Slide 4 text

Logging

Slide 5

Slide 5 text

Problem 5

Slide 6

Slide 6 text

Problem 6

Slide 7

Slide 7 text

Bad Idea System.out.println 7 Messages

Slide 8

Slide 8 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. 8

Slide 9

Slide 9 text

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

Slide 10

Slide 10 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 10

Slide 11

Slide 11 text

Getting Started

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Severity Level 15 TRACE DEBUG INFO WARN ERROR Severity

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

Maven File and Directories 17

Slide 18

Slide 18 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. 18

Slide 19

Slide 19 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. 19

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

SLF4J Logback | Logging 22

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

FileAppender

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

SLF4J Logback | Logging 27

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Encoder

Slide 30

Slide 30 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 30 https://github.com/CSC3100/Tool-Logging

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

SLF4J Logback | Logging 32

Slide 33

Slide 33 text

Questions 33

Slide 34

Slide 34 text

Lab 05. Logger

Slide 35

Slide 35 text

Logger 35 a) Review (and reuse as needed) my code from https://github.com/CSC3100/Tool-Logging b) Include logging elements into your Tic-Tac-Toe code ( try trace/debug and warn/error ) c) Print to screen and save logs on a File.

Slide 36

Slide 36 text

Let’s Work 36

Slide 37

Slide 37 text

CSC 305 Individual Software Design and Development Javier Gonzalez-Sanchez, Ph.D. [email protected] Summer 2024 Copyright. These slides can only be used as study material for the class CSC305 at Cal Poly. They cannot be distributed or used for another purpose.