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

[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdfSteve Caron
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxUnderstanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxSasikiranMarri
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxAS Design & AST.
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfkalichargn70th171
 
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...OnePlan Solutions
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxRTS corp
 
Business Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business AnalysisBusiness Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business AnalysisDEEPRAJ PATHAK
 
Santander Stream Processing with Apache Flink
Santander Stream Processing with Apache FlinkSantander Stream Processing with Apache Flink
Santander Stream Processing with Apache Flinkconfluent
 
full course of software engineering mid term.pdf
full course of software engineering mid term.pdffull course of software engineering mid term.pdf
full course of software engineering mid term.pdfAbdul salam
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Key Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapKey Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapIshara Amarasekera
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
oracle 23c new features for developer and dba
oracle 23c new features for developer and dbaoracle 23c new features for developer and dba
oracle 23c new features for developer and dbaRemote DBA Services
 

Recently uploaded (20)

[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxUnderstanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptx
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
 
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptx
 
Business Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business AnalysisBusiness Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business Analysis
 
Santander Stream Processing with Apache Flink
Santander Stream Processing with Apache FlinkSantander Stream Processing with Apache Flink
Santander Stream Processing with Apache Flink
 
full course of software engineering mid term.pdf
full course of software engineering mid term.pdffull course of software engineering mid term.pdf
full course of software engineering mid term.pdf
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Key Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapKey Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery Roadmap
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
oracle 23c new features for developer and dba
oracle 23c new features for developer and dbaoracle 23c new features for developer and dba
oracle 23c new features for developer and dba
 

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