`
lukejin
  • 浏览: 362147 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

About Logging

    博客分类:
  • Java
阅读更多
Why
在很久很久以前,我曾经问过自己为什么写程序需要记Log呢,只要写的代码完成相应的功能不就Ok了么,
后来逐渐的发现好多系统都有一个log的模块,大到像Windows和Linux这样的操作系统的log,小到Mysql这样的数据库的log,
当我们发现出现了问题我们第一个反应就是去查看其log.所以说Log是查看问题的一个非常有效的途径.
当然通过log我们还可以分析用户的行为.
在C代码的我们可以通过printf来进行输出,在Java里我们可以通过System.out.println()来进行输出,但是有一个问题就是如果通过这个标准输出,既不好控制其是控制台输出还是文件输出,又很难集中控制其输出样式,所以一个功能完备的log系统是很必要的拉.

What
今天我写的是关于Java程序构建Log系统的一些研究.使用的第三方组件为Commons Logging和Log4j
系统和这两个组件之间的依赖关系如下图所示:


也许有些同学没有搞清楚Apache的Commons Logging和Log4J之间的关系,
Commons Logging是一个通用日志框架,其本身提供了一个非常简单的日志功能的实现,但是其强大之处在于可以根据你自己的需求更换具体的日志实现方式,一般情况下我们是使用Log4j的.所以这使得你的代码和具体的日志实现方式进行了解耦.

Commons Logging有两个抽象的实体一个是Log就是用来记日志的,一个是LogFactory是用来创建Log的工厂类.它还包括了一些专业Log工具的包装类以方便你使用那些专业的日志工具进行记日志.
如果你没有显式的声明所使用的Log实现的话,它会去classpath中查看是否有log4j,如果有则使用log4j作为其log的实现,并通过Log4j的包装(wrapper)类进行使用.如果没有继续其他的选择,最后都没有的话就是使用其自身的一个很简单的实现拉.


How
明白上面的思想之后,那我们应该怎么实施呢.


  • 大小: 44.6 KB
  • 大小: 27.9 KB
分享到:
评论

相关推荐

    K8s Cookbook

    This is a practical guide that provides you step-by-step tips and examples to help you build and run your own Kubernetes cluster... The book will also cover important topics about logging and monitoring.

    The DevOps 2.0 Toolkit - Viktor Farcic

    It's about scaling to any number of servers, design of self-healing systems capable of recuperation from both hardware and software failures and about centralized logging and monitoring of the ...

    LabVIEW User Manual

    such as test and measurement, data acquisition, instrument control, datalogging, measurement analysis, and report generation applications. Use this manual to learn about LabVIEW programming features,...

    BlazeDS开发者指南

    About configuration files 31 Chapter 4: Channels and endpoints About channels and endpoints 38 Configuring channels with servlet-based endpoints 43 Channel and endpoint recommendations 49 Using ...

    微软C#企业库Enterprise Library 6 Docs.chm 文档

    About This Release of Enterprise Library Developing Applications with Enterprise Library Design of Enterprise Library The Data Access Application Block The Exception Handling Application Block ...

    Flask Framework Cookbook.pdf 最新 原版

    Learn about efficient and effective debugging, logging, and error handling in Flask Test your applications as you write them to prevent future complications Implement full-text search for effective...

    Learning Elastic Stack 6.0-Packt Publishing(2017).pdf

    Elastic Stack is a powerful combination of tools for the distributed search, analytics, logging, and visualization of data from medium to massive data sets. The newly released Elastic Stack 6.0 brings...

    Expert PHP and MySQL(Apress,2013)

    Error handling is about more than just the mechanics in the PHP syntax, but also about handling MySQL errors, logging those errors, and about hiding information about application internals that error...

    Flask Framework Cookbook

    You will see how to write an admin interface followed by the debugging and logging of errors. Finally, you will learn about different deployment and post-deployment techniques on platforms such as ...

    Learning Elastic Stack 6.0

    The Elastic Stack is a powerful combination of tools for distributed search, analytics, logging, and visualization of data from medium to massive data sets. The newly released Elastic Stack 6.0 brings...

    go系统编程(英文版)

    error logging. Then it introduces you to pattern matching and regular expressions, Go Reflection, and talks about unsafe code. After that, it compares Go to other programming languages and presents ...

    apache kafka教程

    handled by logging the activity out to some kind of file and then periodically aggregating these files for analysis. Operational data is data about the performance of servers (CPU, IO usage, request ...

    Flask Framework Cookbook源码

    debugging and logging of errors in Flask. You will also learn how to make your applications multilingual and gain an insight into the various testing techniques. Finally, you will learn about the ...

    Getting.Started.with.Kubernetes.2017.5 高清完整.pdf版

    Additionally, you will learn about operational aspects of Kubernetes such as monitoring and logging. Advanced concepts such as container security and cluster federation will also be covered. Finally,...

    Effective Python Development for Biologists

    About this book » 1 Typography and formatting » 5 Getting in touch » 8 2: Environments for developing in Python 10 Introduction » 10 What you actually write code in » 10 Integrated development ...

    The+DevOps+2.2+Toolkit_Self-Healing+Clusters-Packt+Publishing(2018).epub

    Microservices, centralized logging, and a few other practices and tools that I used in my projects were part of the initial scope. For that book I had no one behind me. There was no team but me, a ...

    DevOps with Kubernetes 2nd Edition

    Additionally, you will learn about operational aspects of Kubernetes such as monitoring and logging. Advanced concepts such as container security and cluster federation will also be covered. Finally,...

    MongoDB.Data.Modeling.1782175342

    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....

    ad hoc路由协议源代码----TORA routing protocol

    tora_dest.h - destinations the routing protocol knows about tora_neighbor.h - per destination neighbors tora_packet.h - packet definitions tora.cc - basic TORA functionality tora_api.cc - TORA ...

    Drupal 8 Module Development 2nd Edition

    Logging and Mailing Theming Menus and Menu Links Data Modeling and Storage Your Own Custom Entities Database API Your Own Custom Fields Access Control Caching JavaScript in Drupal Multilingual Queues ...

Global site tag (gtag.js) - Google Analytics