SlideShare une entreprise Scribd logo
1  sur  3
Logging Best Practices Using Crypto Logger

Logging can be an invaluable tool during all stages of software development right from development to
deployment/production. Good use of logging enables you to record and report errors, maintain audit trials, gather
app usage statistics and gather performance benchmarks. The following are best practices to be used when using
logging in your software:




Know Who Will Consume And Analyze The Logs

Logging output should make sense to the people who will view/Analyze the logs. For example, logging information
targeted at developers will typically be quite different from that targeted at end-users which in turn will be different
from that targeted at system-administrators. For example, end users are likely to have no use for your logs if you
output messages like "Heap error in function ABC" or "Lock cannot be acquired for polling". Generating the correct
type of logging info is important so that the log information can actually be used and understood by the consumers
of the logs.




Decide Beforehand What Type Of Messages Should Be Used For Each Log Level

Loggers typically provide multiple log levels using which messages can be logged. Each level indicates a different
level of severity and/or detail. Typical levels defined are Debug, Info, Warning, Error and Fatal. It is important that
all the members of your team agree beforehand on the type of messages to be used with each log level. This is
necessary so that a log generated during a routine run of the software does not get flooded with Debug log
messages. Similarly, important information which should have the Warning, Error or Fatal levels should not be
logged using the Debug or Info levels. Since there are no hard and fast rules for what constitutes the informational
detail and/or severity associated with each level, it is upto your team to decide this beforehand.

Crypto Logger provides the following levels and guidelines/conventions for when each level should be used:


  Level     Description

          Used during debugging and development of your software. Specifies the maximum level of detail - a
  Debug
          Logger set at Debug level allows all log entries to be written.
          Used when detailed logging info is needed from your software. A Logger set to this level allows only log
 Detailed
          entries with their levels set to Detailed or higher.
          Used during normal operation of your software. A Logger set to this level allows only log entries with
 Normal
          their level set to Normal or higher.
          Used to limit generated logging information to only warnings or more serious conditions during the
 Warning operation of your software. A Logger set to this level allows only log entries with their level set to
          Warning or higher.
          Used to limit generated logging information to only errors or fatal conditions during the operation of
  Error
          your software. A Logger set to this level allows only log entries with their level set to Error or Fatal.
          Used to limit generated logging information to only fatal conditions during the operation of your
  Fatal
          software. A Logger set to this level allows only log entries with their level set to Fatal.




Log Only As Much As Needed

Logging code is not free - it increases the size of your code and your compiled binaries. Further, the logging code
itself consumes processor time to run. Logging code also requires maintenance just like any other code. Keep these
factors in mind when deciding how much and what type of data to log. You should not log the code execution
progress after each line of code, nor should you produce useless logs contain very little info like "Failure!". Use
your judgment when deciding the quantity and quality of data to log that will provide useful information when it
actually comes time to view and Analyze the logs to resolve issues or gather statistics.
Use External Configuration Files

Logging should be configured via an external configuration file so that the log outputs, level, verbosity, etc can be
easily configured without having to recompile your software.

Crypto Logger supports simple XML configuration files. It can also watch external configuration files for changes - if
the file changes, Crypto Logger will automatically reconfigure itself using the changed file.




Ship Production Apps With Logging Configured To Produce Less Log Information

Typically, you should ship production apps that are configured (via external configuration files) to only output Info,
Warning, Error Or Fatal log messages. Only if the software encounters a problem should it be configured (again, via
a configuration file) to output Debug level log messages which can help in trouble-shooting the problem.




Use Buffered Mode To Avoid Repeated Costly Writes To Disk, Network, etc

If you output log messages to targets like disks, or tcp, which are costly in terms of write times, considered using
the buffered mode of your logging software. When a certain quantity of log data is Buffered, all Buffered log data is
written at once which typically saves a considerable amount of time.

Crypto Logger has full support for buffered mode and various triggers which induce flushing.




Use Asynchronous Mode For Performance Critical Code

When logging from performance-critical code, consider using the Asynchronous mode of your logging software. In
Asynchronous mode, log data is Buffered and is written on a background thread so that your performance-critical
code does not wait for the log data to be written.

Crypto Logger has full support for asynchronous mode.




Prepare Data To Be Logged Only If Logging Is Enabled At The Desired Level

Before formatting or otherwise preparing the data to be logged, check that logging is enabled at the desired level
so that time is not wasted in the formatting/preparation of the data.

For example, instead of doing this:

log.MainSession.LogMessage(string.Format("Current time is {0}",DateTime.Now));

use following code:

if(log.MainSession.IsEnabled(LogEntryLevel.Debug))
    log.MainSession.LogMessage(string.Format("Current time is {0}",DateTime.Now));
Crypto Logger comes with log method overloads which take all format parameters so that you do not have to check
for level and your code remains clean and minimal.




Keep Logging Code Error Free

You should take care that the logging code itself does not cause undesirable effects. The logging code should
remain as transparent as possible to the actual execution of the software and should not cause exceptions, errors,
deadlocks, slowness or other undesirable effects.

This is the overriding principle that is used in the design of Crypto Logger - logging should not alter the behavior or
flow of your software. Any exceptions or errors that occur during logging are handled gracefully and the execution
of the host software continues uninterrupted.




Keep Logging Code In Sync With The Software Code

Many times, the code surrounding the logging code changes, but the log messages are not changed or removed or
added to reflect the changed code. Such out-of-sync logging code may not be very useful in providing helpful
information when the log is viewed or analyzed. So, just like comments, it is important that the log messages and
logging code is updated when the software code changes.

Contenu connexe

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

En vedette

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

En vedette (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Logging best practices using crypto logger

  • 1. Logging Best Practices Using Crypto Logger Logging can be an invaluable tool during all stages of software development right from development to deployment/production. Good use of logging enables you to record and report errors, maintain audit trials, gather app usage statistics and gather performance benchmarks. The following are best practices to be used when using logging in your software: Know Who Will Consume And Analyze The Logs Logging output should make sense to the people who will view/Analyze the logs. For example, logging information targeted at developers will typically be quite different from that targeted at end-users which in turn will be different from that targeted at system-administrators. For example, end users are likely to have no use for your logs if you output messages like "Heap error in function ABC" or "Lock cannot be acquired for polling". Generating the correct type of logging info is important so that the log information can actually be used and understood by the consumers of the logs. Decide Beforehand What Type Of Messages Should Be Used For Each Log Level Loggers typically provide multiple log levels using which messages can be logged. Each level indicates a different level of severity and/or detail. Typical levels defined are Debug, Info, Warning, Error and Fatal. It is important that all the members of your team agree beforehand on the type of messages to be used with each log level. This is necessary so that a log generated during a routine run of the software does not get flooded with Debug log messages. Similarly, important information which should have the Warning, Error or Fatal levels should not be logged using the Debug or Info levels. Since there are no hard and fast rules for what constitutes the informational detail and/or severity associated with each level, it is upto your team to decide this beforehand. Crypto Logger provides the following levels and guidelines/conventions for when each level should be used: Level Description Used during debugging and development of your software. Specifies the maximum level of detail - a Debug Logger set at Debug level allows all log entries to be written. Used when detailed logging info is needed from your software. A Logger set to this level allows only log Detailed entries with their levels set to Detailed or higher. Used during normal operation of your software. A Logger set to this level allows only log entries with Normal their level set to Normal or higher. Used to limit generated logging information to only warnings or more serious conditions during the Warning operation of your software. A Logger set to this level allows only log entries with their level set to Warning or higher. Used to limit generated logging information to only errors or fatal conditions during the operation of Error your software. A Logger set to this level allows only log entries with their level set to Error or Fatal. Used to limit generated logging information to only fatal conditions during the operation of your Fatal software. A Logger set to this level allows only log entries with their level set to Fatal. Log Only As Much As Needed Logging code is not free - it increases the size of your code and your compiled binaries. Further, the logging code itself consumes processor time to run. Logging code also requires maintenance just like any other code. Keep these factors in mind when deciding how much and what type of data to log. You should not log the code execution progress after each line of code, nor should you produce useless logs contain very little info like "Failure!". Use your judgment when deciding the quantity and quality of data to log that will provide useful information when it actually comes time to view and Analyze the logs to resolve issues or gather statistics.
  • 2. Use External Configuration Files Logging should be configured via an external configuration file so that the log outputs, level, verbosity, etc can be easily configured without having to recompile your software. Crypto Logger supports simple XML configuration files. It can also watch external configuration files for changes - if the file changes, Crypto Logger will automatically reconfigure itself using the changed file. Ship Production Apps With Logging Configured To Produce Less Log Information Typically, you should ship production apps that are configured (via external configuration files) to only output Info, Warning, Error Or Fatal log messages. Only if the software encounters a problem should it be configured (again, via a configuration file) to output Debug level log messages which can help in trouble-shooting the problem. Use Buffered Mode To Avoid Repeated Costly Writes To Disk, Network, etc If you output log messages to targets like disks, or tcp, which are costly in terms of write times, considered using the buffered mode of your logging software. When a certain quantity of log data is Buffered, all Buffered log data is written at once which typically saves a considerable amount of time. Crypto Logger has full support for buffered mode and various triggers which induce flushing. Use Asynchronous Mode For Performance Critical Code When logging from performance-critical code, consider using the Asynchronous mode of your logging software. In Asynchronous mode, log data is Buffered and is written on a background thread so that your performance-critical code does not wait for the log data to be written. Crypto Logger has full support for asynchronous mode. Prepare Data To Be Logged Only If Logging Is Enabled At The Desired Level Before formatting or otherwise preparing the data to be logged, check that logging is enabled at the desired level so that time is not wasted in the formatting/preparation of the data. For example, instead of doing this: log.MainSession.LogMessage(string.Format("Current time is {0}",DateTime.Now)); use following code: if(log.MainSession.IsEnabled(LogEntryLevel.Debug)) log.MainSession.LogMessage(string.Format("Current time is {0}",DateTime.Now));
  • 3. Crypto Logger comes with log method overloads which take all format parameters so that you do not have to check for level and your code remains clean and minimal. Keep Logging Code Error Free You should take care that the logging code itself does not cause undesirable effects. The logging code should remain as transparent as possible to the actual execution of the software and should not cause exceptions, errors, deadlocks, slowness or other undesirable effects. This is the overriding principle that is used in the design of Crypto Logger - logging should not alter the behavior or flow of your software. Any exceptions or errors that occur during logging are handled gracefully and the execution of the host software continues uninterrupted. Keep Logging Code In Sync With The Software Code Many times, the code surrounding the logging code changes, but the log messages are not changed or removed or added to reflect the changed code. Such out-of-sync logging code may not be very useful in providing helpful information when the log is viewed or analyzed. So, just like comments, it is important that the log messages and logging code is updated when the software code changes.