像日志的这样的小细节,在开发过程中常常被忽略。除了区分级别外,日志的输出内容通常处理地很随意。而实际上日志在监控系统行为,排错,性能优化,安全审计等方面扮演着重要的角色。
总体上说一份良好的日志应该符合一个特性:greppable。grep是unix/linux系统上一个很强大的工具,它能够从文件中找出匹配某个正则表达式的所有行。也就是说良好的日志文件应该能够让日志分析工具在庞大的日志数据里很容易很精准地定位到所需要的信息。
至于如何才算greppable,还得看具体的分析需求,总结一下考虑的因素大概有以下几个方面:
一、what to log? 需要纪录哪些信息
错误信息,核心性能数据,用户行为数据,安全验证信息等等,要根据将来需要对日志做哪些分析来选择纪录相应的数据
二、log design
1、单独的日志信息要纪录在一行数据里面,因为像grep之类的工具无法跨行匹配,如果一条日志信息会跨行的话,会加大日志分析的难度
2、日志要纪录分析所需的必要信息,并且要避免冗余,与其它无关的信息区分开来,方便分析工具快速定位核心信息
3、日志文件要分级与模块化,不同的模块对应不同的日志文件,易于快速定位问题
总结:好的日志应该准确纪录系统的行为,而且在内容与格式上是grep-friendly,能够让日志分析工具在庞大的日志文件里很容易很精准地定位到所需要的数据
分享到:
相关推荐
Chapter 9: Best Practices for Function-Based Views Chapter 10: Best Practices for Class-Based Views Chapter 11: Form Fundamentals Chapter 12: Common Patterns for Forms Chapter 13: Templates: Best ...
Next, you'll discover the best practices in logging, operations, knowledge management, searching, and reporting. To finish off, we will teach you how to troubleshoot Splunk searches, as well as ...
Defensive Security Handbook: Best Practices for Securing Infrastructure by Lee Brotherston English | 3 Apr. 2017 | ASIN: B06Y18XC5Y | 268 Pages | AZW3 | 3.88 MB Despite the increase of high-profile ...
Just as important as following best practices is the ability to measure your own performance, so that you can adjust as times change, and so that you can note the subtle nuances in your own code and ...
I wanted to write a book about best practices in Django, except Two Scoops is that book, no need to write another one. -- Buddy Lindsey, Host of GoDjango Audrey's illustrations reinforce Audrey and ...
Flask Framework Cookbook takes you ...By the end of this book, you will have gained all the knowledge required to write Flask applications in the best possible way, and scale them with best practices.
The authors provide in-depth implementation guidance and best practices for access control, cryptography, logging, secure coding, and authentication and authorization in web application development....
Brings together practical best practices for Java, TDD, and OO design Walks through setting up Java 5.0 and writing your first program Covers all the basics, including strings, packages, and more ...
Finally, we will talk about best practices that will help you optimize and manage your database, presenting you with a real-life example of data modeling on a real-time logging analytics application.
About This Book Get the most out of ...By the end of this book, you will have gained all the knowledge required to write Flask applications in the best possible way, and scale them with best practices.
Hands-On Continuous Integration and Delivery starts ...By the end of this book, you will have a detailed understanding of best practices for CI/CD systems and be able to implement them with confidence.
This tutorial explains how to set up log4j with email, files and stdout. It compares XML to properties configuration files, ...Furthermore, we explain best practices on logging and exception handling.
Discover how to apply software development best practices to improve performance, productivity, and quality in your Storm projects Who This Book Is For This book is intended for Python developers who ...
Chapter 6, Security Writing Secure Code, discusses the security aspect of architecture and teaches you best practices and techniques of writing applications that are secure. You will understand the ...
Finally, we will talk about best practices that will help you optimize and manage your database, presenting you with a real-life example of data modeling on a real-time logging analytics application....
You’ll learn how to use the Varnish Configuration Language and HTTP best practices to achieve faster performance and a higher hit rate. Understand how Varnish helps you gain optimum web performance...
Next, you’ll master best practices for securely administering accounts, devices, services, processes, data, and networks. Then, you’ll master powerful tools and automated scripting techniques for ...
Discover your complete guide to designing, deploying, and managing OpenStack-based clouds in mid-to-large IT infrastructures with best practices, expert understanding, and more About This Book ...
Best practices for authentication, access control, data protection, attack prevention, error handling, and much more are included. Using the practical advice and real-world examples provided in this ...
Detailed guidance on Mesos best practices in a stable production environment Who This Book Is For This book is intended for developers and operators who want to build and run scalable and fault-...