SlideShare a Scribd company logo
1 of 47
Download to read offline
LOGS IN CODE
MODEN APPLICATION
Jannarong Wadthong


1/Sept/2020
▸ Part I — Software Development and S.O.L.I.D ~ 10 mins


▸ Part II — Logs in Code ~ 30 mins


▸ Part III — Logs in Architecture ~ 15 mins


▸ Part IV — Log Framework ~ xx mins
SOFTWARE DEVELOPMENT
AND S.O.L.D
PART I
S.O.L.I.D
S.O.L.I.D
S.O.L.I.D
TEXT
MAINTAINABILITY CAN BE QUANTIFIED:
▸ Extensibility — how hard is it to add features


▸ Stability — how hard is it to make changes?


▸ Understandability — how hard is it for someone else to pick
up your code?
S.O.L.I.D
12 PRINCIPLES BEHIND THE AGILE MANIFESTO
HOW TO AVOID TECHNICAL DEBT?
▸ Avoid code smells as you go, and practice regular
refactoring. Don’t Repeat Yourself (DRY), use clear &
consistent variable & method names, practice Test Driven
Development (TDD), follow the Single Responsibility
Principle (SRP), avoid long/complex methods, and
maintain thin interfaces / don’t hard-code


▸ Conduct code reviews.


▸ Use automated testing.
LOGS IN CODE
PART II
PUBLIC VS INTERNAL BANKING API
▸ Transfer Money API


▸ Deposit Money API


▸ Withdrawal Money API
TEXT
PUBLIC TRANSFER MONEY FLOW
CONTROLLER ACCEPTS
REQUEST
CONTROLLER ACK BACK TO USER
CHECK BALANCE WITHDRAW DEPOSIT
CHECK
AUTHORISATION
TEXT
INTERNAL TRANSFER MONEY FLOW
CONTROLLER ACCEPTS
REQUEST
CONTROLLER ACK BACK TO USER
CHECK BALANCE WITHDRAW DEPOSIT
INTERNAL TRANSFER
void transfer(Account fromAcc, Account toAcc, int amount) throws Exception {


if (fromAcc.getBalance() < amount)


throw new InsufficientFundsException();




fromAcc.withdraw(amount);


toAcc.deposit(amount);


}
PUBLIC TRANSFER
void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception {




if (!isUserAuthorised(user, fromAcc)) {


logger.info("User has no permission.");


throw new UnauthorisedUserException();


}




if (fromAcc.getBalance() < amount) {


logger.info("Insufficient funds.");


throw new InsufficientFundsException();


}


fromAcc.withdraw(amount);


toAcc.deposit(amount);


}
PUBLIC TRANSFER WITH PERFORMANCE LOGGING
void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception {


long startTime = currentTime();


if (!isUserAuthorised(user, fromAcc)) {


logger.info("User has no permission.");


throw new UnauthorisedUserException();


}




if (fromAcc.getBalance() < amount) {


logger.info("Insufficient funds.");


throw new InsufficientFundsException();


}


fromAcc.withdraw(amount);


toAcc.deposit(amount);


long endTime = currentTime();


logger.info("Execution time:" + (endTime - startTime);


}
S.O.L.I.D
S.O.L.I.D — HOW?
TEXT
WITHDRAW MONEY
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
CONTROLLER
CHECK BALANCE
DO WITHDRAW
START TIME
END TIME
START TIME
END TIME
TEXT
DEPOSIT MONEY
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
CONTROLLER
DO DEPOSIT
START TIME
END TIME
START TIME
END TIME
TEXT
TRANSFER MONEY
CONTROLLER
CHECK BALANCE
WITHDRAW
CHECK AUTHORISATION
DEPOSIT
START TIME
END TIME
CONTROLLER
CHECK BALANCE
WITHDRAW
DEPOSIT
START TIME
END TIME
TEXT
WITHDRAW MONEY
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
CONTROLLER
CHECK BALANCE
DO WITHDRAW
START TIME
END TIME
START TIME
END TIME
DO WITHDRAW
TEXT
DEPOSIT MONEY
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
CONTROLLER
DO DEPOSIT
START TIME
END TIME
START TIME
END TIME
DO DEPOSIT
ALL PUBLIC API
WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
WITHDRAW
CHECK AUTHORISATION
DEPOSIT
START TIME
END TIME
DEPOSIT TRANSFER
ALL PUBLIC API
WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
WITHDRAW
CHECK AUTHORISATION
DEPOSIT
START TIME
END TIME
DEPOSIT TRANSFER
PERFORMANCE LOGGING CONCERN
ALL PUBLIC API
WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
WITHDRAW
CHECK AUTHORISATION
DEPOSIT
START TIME
END TIME
DEPOSIT TRANSFER
PERFORMANCE LOGGING CONCERN SECURITY CONCERN
PROBLEM HAVING LOGS IN CODE
PROBLEM HAVING LOGS IN CODE
PROBLEM HAVING LOGS IN CODE
PROBLEM HAVING LOGS IN CODE
CODE TANGLING AND CODE SCATTERING
WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
WITHDRAW
CHECK AUTHORISATION
DEPOSIT
START TIME
END TIME
DEPOSIT TRANSFER
PERFORMANCE LOGGING CONCERN SECURITY CONCERN
CODE TANGLING AND CODE SCATTERING
WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CONTROLLER
DO DEPOSIT
CONTROLLER
CHECK BALANCE
WITHDRAW
DEPOSIT
DEPOSIT TRANSFER
PERFORMANCE LOGGING ASPECT SECURITY ASPECT
WE WANT THIS
@LogExecutionTime


@Authorize


void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception {


checkBalance(fromAcc);


fromAcc.withdraw(amount);


toAcc.deposit(amount);


}
TEXT
AOP IMPLEMENTATION: DYNAMIC PROXY
@Aspect


Performance Logging Proxy


1.start time


2.end time
ATMController Target Service
+ transfer()


+ withdraw()


+ deposit()
As you can see from that diagram, the proxy has one job.
• Opening and closing times.
• And then delegating to the real target service, the one we wrote.
• And ATMController will never know that they are talking to a proxy, and not the real thing.
2 MARKERS: @BEFORE AND @AFTER
OR 1 MARKER: @AROUND
TEXT
AOP IMPLEMENTATION
@Aspect


Authorisation Proxy


1.check if user is valid


ATMController Real ATMService
+ transfer()


+ withdraw()


+ deposit()
1 MARKER: @BEFORE
TEXT
ASPECT
@Aspect
public class PerformanceAspect {
@Around("@annotation(LogExecutionTime)")
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
Object proceed = joinPoint.proceed();
long executionTime = System.currentTimeMillis() - start;
log.info(joinPoint.getSignature() + " executed in " + executionTime + "ms");
return proceed;
}
}
LOGS IN ARCHITECTURE
PART III
This slide is intentionally left blank :)
TEXT
LOGS IN ACTION
▸ Troubleshooting


▸ Law


▸ User behaviours
TEXT
PUBLIC TRANSFER MONEY FLOW
TEXT
LOG FRAMEWORK: IMPLEMENTATION
LOG
HARDDISK
STOUT REST API
DATABASE
TEXT FILE
PROMETHEUS GRAFANA
TEXT
TEXT
TEXT
SUMMARY
Begin/End Transaction


Transaction Error Hand
TEXT
THANK YOU

More Related Content

What's hot

JavaScript promise
JavaScript promiseJavaScript promise
JavaScript promiseeslam_me
 
Smart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSmart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSittiphol Phanvilai
 
Demoiselle 2.0 no JavaOne Brasil 2010
Demoiselle 2.0 no JavaOne Brasil 2010Demoiselle 2.0 no JavaOne Brasil 2010
Demoiselle 2.0 no JavaOne Brasil 2010Cleverson Sacramento
 
The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196Mahmoud Samir Fayed
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script PromiseAlok Guha
 
Xtext @ Profict Summer Camp
Xtext @ Profict Summer CampXtext @ Profict Summer Camp
Xtext @ Profict Summer CampSven Efftinge
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsKonrad Malawski
 
Reactive programming with RxSwift
Reactive programming with RxSwiftReactive programming with RxSwift
Reactive programming with RxSwiftScott Gardner
 
Functional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwiftFunctional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwiftRodrigo Leite
 
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline codeRajeev Sharan
 
Trisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorTrisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorEthanTu
 
Async js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgariaAsync js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgariaHackBulgaria
 
The account problem in Java and Clojure
The account problem in Java and ClojureThe account problem in Java and Clojure
The account problem in Java and ClojureAlf Kristian Støyle
 

What's hot (19)

JavaScript promise
JavaScript promiseJavaScript promise
JavaScript promise
 
Smart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSmart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathon
 
Demoiselle 2.0 no JavaOne Brasil 2010
Demoiselle 2.0 no JavaOne Brasil 2010Demoiselle 2.0 no JavaOne Brasil 2010
Demoiselle 2.0 no JavaOne Brasil 2010
 
The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script Promise
 
Clojure workshop
Clojure workshopClojure workshop
Clojure workshop
 
Xtext @ Profict Summer Camp
Xtext @ Profict Summer CampXtext @ Profict Summer Camp
Xtext @ Profict Summer Camp
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
Reactive programming with RxSwift
Reactive programming with RxSwiftReactive programming with RxSwift
Reactive programming with RxSwift
 
Functional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwiftFunctional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwift
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
Introduction to typescript
Introduction to typescriptIntroduction to typescript
Introduction to typescript
 
Oop assignment 02
Oop assignment 02Oop assignment 02
Oop assignment 02
 
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline code
 
ES2015 promise
ES2015 promiseES2015 promise
ES2015 promise
 
Trisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorTrisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptor
 
Async js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgariaAsync js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgaria
 
The account problem in Java and Clojure
The account problem in Java and ClojureThe account problem in Java and Clojure
The account problem in Java and Clojure
 

Similar to Logging in code

Introduction to aop
Introduction to aopIntroduction to aop
Introduction to aopDror Helper
 
A Journey with React
A Journey with ReactA Journey with React
A Journey with ReactFITC
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd marchRajeev Sharan
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right wayThibaud Desodt
 
Formal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction ContractsFormal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction ContractsGera Shegalov
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of ControlChad Hietala
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy codeShriKant Vashishtha
 
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...Stanfy
 
Taming event-driven software via formal verification
Taming event-driven software via formal verificationTaming event-driven software via formal verification
Taming event-driven software via formal verificationAdaCore
 
README.MD for building the first purely digital mobile bank in Indonesia
README.MD for building the first purely digital mobile bank in Indonesia README.MD for building the first purely digital mobile bank in Indonesia
README.MD for building the first purely digital mobile bank in Indonesia Richard Radics
 
Formal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractFormal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractGera Shegalov
 
Ruslan Platonov - Transactions
Ruslan Platonov - TransactionsRuslan Platonov - Transactions
Ruslan Platonov - TransactionsDmitry Buzdin
 
Test First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in GrailsTest First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in GrailsTim Berglund
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Massimo Oliviero
 
Test First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTest First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTim Berglund
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Patterngoodfriday
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every dayVadym Khondar
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in reactBOSC Tech Labs
 
Aspect-Oriented Programming
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented ProgrammingAndrey Bratukhin
 

Similar to Logging in code (20)

Introduction to aop
Introduction to aopIntroduction to aop
Introduction to aop
 
A Journey with React
A Journey with ReactA Journey with React
A Journey with React
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 
Formal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction ContractsFormal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction Contracts
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
 
Taming event-driven software via formal verification
Taming event-driven software via formal verificationTaming event-driven software via formal verification
Taming event-driven software via formal verification
 
README.MD for building the first purely digital mobile bank in Indonesia
README.MD for building the first purely digital mobile bank in Indonesia README.MD for building the first purely digital mobile bank in Indonesia
README.MD for building the first purely digital mobile bank in Indonesia
 
Formal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractFormal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction Contract
 
Ruslan Platonov - Transactions
Ruslan Platonov - TransactionsRuslan Platonov - Transactions
Ruslan Platonov - Transactions
 
Test First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in GrailsTest First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in Grails
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)
 
Test First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTest First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in Grails
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
Aspect-Oriented Programming
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented Programming
 
ELEVATE Paris
ELEVATE ParisELEVATE Paris
ELEVATE Paris
 

Recently uploaded

Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfVictor Lopez
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems ApproachNeo4j
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfMehmet Akar
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationHelp Desk Migration
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024vaibhav130304
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Gáspár Nagy
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1KnowledgeSeed
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfmbmh111980
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdfkalichargn70th171
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...naitiksharma1124
 
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityAPVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityamy56318795
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfsteffenkarlsson2
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)Max Lee
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...rajkumar669520
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...Alluxio, Inc.
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignNeo4j
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfFurqanuddin10
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersEmilyJiang23
 

Recently uploaded (20)

Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityAPVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
 

Logging in code

  • 1. LOGS IN CODE MODEN APPLICATION Jannarong Wadthong 1/Sept/2020
  • 2. ▸ Part I — Software Development and S.O.L.I.D ~ 10 mins ▸ Part II — Logs in Code ~ 30 mins ▸ Part III — Logs in Architecture ~ 15 mins ▸ Part IV — Log Framework ~ xx mins
  • 7. TEXT MAINTAINABILITY CAN BE QUANTIFIED: ▸ Extensibility — how hard is it to add features ▸ Stability — how hard is it to make changes? ▸ Understandability — how hard is it for someone else to pick up your code?
  • 9. 12 PRINCIPLES BEHIND THE AGILE MANIFESTO
  • 10. HOW TO AVOID TECHNICAL DEBT? ▸ Avoid code smells as you go, and practice regular refactoring. Don’t Repeat Yourself (DRY), use clear & consistent variable & method names, practice Test Driven Development (TDD), follow the Single Responsibility Principle (SRP), avoid long/complex methods, and maintain thin interfaces / don’t hard-code ▸ Conduct code reviews. ▸ Use automated testing.
  • 12. PUBLIC VS INTERNAL BANKING API ▸ Transfer Money API ▸ Deposit Money API ▸ Withdrawal Money API
  • 13. TEXT PUBLIC TRANSFER MONEY FLOW CONTROLLER ACCEPTS REQUEST CONTROLLER ACK BACK TO USER CHECK BALANCE WITHDRAW DEPOSIT CHECK AUTHORISATION
  • 14. TEXT INTERNAL TRANSFER MONEY FLOW CONTROLLER ACCEPTS REQUEST CONTROLLER ACK BACK TO USER CHECK BALANCE WITHDRAW DEPOSIT
  • 15. INTERNAL TRANSFER void transfer(Account fromAcc, Account toAcc, int amount) throws Exception { if (fromAcc.getBalance() < amount) throw new InsufficientFundsException(); fromAcc.withdraw(amount); toAcc.deposit(amount); }
  • 16. PUBLIC TRANSFER void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception { if (!isUserAuthorised(user, fromAcc)) { logger.info("User has no permission."); throw new UnauthorisedUserException(); } if (fromAcc.getBalance() < amount) { logger.info("Insufficient funds."); throw new InsufficientFundsException(); } fromAcc.withdraw(amount); toAcc.deposit(amount); }
  • 17. PUBLIC TRANSFER WITH PERFORMANCE LOGGING void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception { long startTime = currentTime(); if (!isUserAuthorised(user, fromAcc)) { logger.info("User has no permission."); throw new UnauthorisedUserException(); } if (fromAcc.getBalance() < amount) { logger.info("Insufficient funds."); throw new InsufficientFundsException(); } fromAcc.withdraw(amount); toAcc.deposit(amount); long endTime = currentTime(); logger.info("Execution time:" + (endTime - startTime); }
  • 20. TEXT WITHDRAW MONEY CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION CONTROLLER CHECK BALANCE DO WITHDRAW START TIME END TIME START TIME END TIME
  • 21. TEXT DEPOSIT MONEY CONTROLLER DO DEPOSIT CHECK AUTHORISATION CONTROLLER DO DEPOSIT START TIME END TIME START TIME END TIME
  • 22. TEXT TRANSFER MONEY CONTROLLER CHECK BALANCE WITHDRAW CHECK AUTHORISATION DEPOSIT START TIME END TIME CONTROLLER CHECK BALANCE WITHDRAW DEPOSIT START TIME END TIME
  • 23. TEXT WITHDRAW MONEY CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION CONTROLLER CHECK BALANCE DO WITHDRAW START TIME END TIME START TIME END TIME DO WITHDRAW
  • 24. TEXT DEPOSIT MONEY CONTROLLER DO DEPOSIT CHECK AUTHORISATION CONTROLLER DO DEPOSIT START TIME END TIME START TIME END TIME DO DEPOSIT
  • 25. ALL PUBLIC API WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER DO DEPOSIT CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE WITHDRAW CHECK AUTHORISATION DEPOSIT START TIME END TIME DEPOSIT TRANSFER
  • 26. ALL PUBLIC API WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER DO DEPOSIT CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE WITHDRAW CHECK AUTHORISATION DEPOSIT START TIME END TIME DEPOSIT TRANSFER PERFORMANCE LOGGING CONCERN
  • 27. ALL PUBLIC API WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER DO DEPOSIT CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE WITHDRAW CHECK AUTHORISATION DEPOSIT START TIME END TIME DEPOSIT TRANSFER PERFORMANCE LOGGING CONCERN SECURITY CONCERN
  • 32. CODE TANGLING AND CODE SCATTERING WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER DO DEPOSIT CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE WITHDRAW CHECK AUTHORISATION DEPOSIT START TIME END TIME DEPOSIT TRANSFER PERFORMANCE LOGGING CONCERN SECURITY CONCERN
  • 33. CODE TANGLING AND CODE SCATTERING WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CONTROLLER DO DEPOSIT CONTROLLER CHECK BALANCE WITHDRAW DEPOSIT DEPOSIT TRANSFER PERFORMANCE LOGGING ASPECT SECURITY ASPECT
  • 34. WE WANT THIS @LogExecutionTime @Authorize void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception { checkBalance(fromAcc); fromAcc.withdraw(amount); toAcc.deposit(amount); }
  • 35. TEXT AOP IMPLEMENTATION: DYNAMIC PROXY @Aspect 
 Performance Logging Proxy 1.start time 2.end time ATMController Target Service + transfer() + withdraw() + deposit() As you can see from that diagram, the proxy has one job. • Opening and closing times. • And then delegating to the real target service, the one we wrote. • And ATMController will never know that they are talking to a proxy, and not the real thing. 2 MARKERS: @BEFORE AND @AFTER OR 1 MARKER: @AROUND
  • 36. TEXT AOP IMPLEMENTATION @Aspect 
 Authorisation Proxy 1.check if user is valid ATMController Real ATMService + transfer() + withdraw() + deposit() 1 MARKER: @BEFORE
  • 37. TEXT ASPECT @Aspect public class PerformanceAspect { @Around("@annotation(LogExecutionTime)") public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { long start = System.currentTimeMillis(); Object proceed = joinPoint.proceed(); long executionTime = System.currentTimeMillis() - start; log.info(joinPoint.getSignature() + " executed in " + executionTime + "ms"); return proceed; } }
  • 39. This slide is intentionally left blank :)
  • 40. TEXT LOGS IN ACTION ▸ Troubleshooting ▸ Law ▸ User behaviours
  • 42. TEXT LOG FRAMEWORK: IMPLEMENTATION LOG HARDDISK STOUT REST API DATABASE TEXT FILE PROMETHEUS GRAFANA
  • 43. TEXT
  • 44. TEXT
  • 45. TEXT