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

Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 

Recently uploaded (20)

Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 

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