SSH (iii) resource classification and log management

Source: Internet
Author: User

The previous blog post has separately described how to build SSH development environment and the SSH integration of three frameworks. After the integration is complete, we can basically start a project based on the SSH framework. The resource classification and log management described in this blog post are some of the icing on the cake. Use these to clear our ideas and facilitate our programming.

Let's talk about resource classification first. The resource classification here refers to a classification management of code or configuration files in a project. The classification in the following is only a reference, mainly for the management of resource classification of the ideological attention. We need to know that a project with a clear structure and a simple skeleton is extremely convenient for team development and can also speed up the understanding of new or other people on the project.


In other words, log management, generally a slightly larger project will be added to log management. The log module is basically an essential part, it plays a very important role in debugging, recording running and problem locating . Many of our common logging tools are:sf4j, Commons-logging,log4j,JDKcomes withLoggingand so on. The common functions and usage of these log frameworks are broadly the same. What I'm trying to say here is,sf4j, it differs fromlog4jorLoggingand other log tools. sf4j is a tool for managing log tools . It was added to address changes in the log framework in the project, such as the startlog4j, but later for some reason want to change tocommons-logging, if you use thesf4j, developers only need to callslf4j, and thenslf4jDepending on the developer's participation in the differentJarpackage to invoke the appropriate logging tool.

The log Tools We use in the current project are sf4j and log4j, which are used by log4j we need to join Jar Package:


    log4j consists of three important components: priority of the log information , the output destination of the log information A the output format for the log information . The priority of log information is from high to low with fatal e rror, WARN, info, DEBUG, respectively, to specify the importance of this log information; the output destination of the log information specifies whether the log will be printed to the console or the file, and the output format controls the display of the log information.

The priority level of the log information FATAL,Error, WARN, INFO, DEBUG are respectively represented: Critical errors, errors, warnings, general information, debugging information .

For log level settings, in the log4j.properties file:

# # Direct logmessages to stdout # # #log4j. appender.stdout= org.apache.log4j.consoleappenderlog4j.appender.stdout.target=system.outlog4j.appender.stdout.layout= org.apache.log4j.patternlayoutlog4j.appender.stdout.layout.conversionpattern=%d{absolute}%5p%c{1}:%L-%m%n # # # Direct Messagesto File Hibernate.log # # # #log4j. appender.file=org.apache.log4j.fileappender# log4j.appender.file.file=hibernate.log#log4j.appender.file.layout=org.apache.log4j.patternlayout#  log4j.appender.file.layout.conversionpattern=%d{absolute}%5p%c{1}:%l-%m%n # # # Set Log levels-for more verbose logging Change ' info ' to ' debug ' # # # log4j.rootlogger=error,stdout #log4j. logger.org.hibernate=info# Log4j.logger.org.hibernate=debuglog4j.logger.cn.itcast.oa=debug

     Log4j.rootlogger=error,stdout

by defining the level here, you can control the switch to the appropriate level of log information in your application. For example, if the info level is defined here, the log information for all debug levels in the application will not be printed.

     Log4j.logger.cn.itcast.oa=debug
is to set the log level of a package in a project individually.

by adding jar packages and configuration files, we can manage our projects with logs. Here's a test I'm adding to the log. Test Class Code:

Package Cn.itcast.oa.test;import Org.apache.commons.logging.log;import org.apache.commons.logging.LogFactory; Import Org.junit.test;public class Logtest {private log log = Logfactory.getlog (This.getclass ()); @Testpublic void Test () {Log.debug ("This is Debug Information"), Log.info ("This is Info"), Log.warn ("This is the Warn Information"); Log.error ("This is the error message"); Log.fatal ("This is fatal information" );}}

When we set different log levels in the log4j.properties configuration file, the information that the console prints should also vary. First look at the log level for debug:

    Log4j.rootlogger=debug,stdout

Debug is the lowest level, should be higher than its level of the log should be printed out. The results shown are:


Look again and set the log level to error. Log-level information that is lower than it should not be printed.

    Log4j.rootlogger=error,stdout

The results shown are:


At this point, we have a basic understanding of resource classification and log management, and we need to continue to explore the project in detail.

SSH (iii) resource classification and log management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.