JAVA Nisshi buried point

 

 JAVA log buried point usage summary:

Environment: jdk1.7, tomcat7, win10, maven 3.2.5

 

1. Delete all log jar packages in the application

2. Import the unslog jar package

  

<dependency>
     <groupId>com.uns.inf</groupId>
     <artifactId>unslog</artifactId>
     <version>1.0.0</version>
</dependency>

 

3. Append unslog.properties to the resource directory (optional)

The content is as follows:

#Project name (engineered projects are automatically obtained, no need to modify)
app_name=${projectName}
# log level
#log_level=info
#log storage days
#maxHistory=30
#Whether the business buried point is output (true output false is closed, the default is closed)
#bizlog=true
#Console log close (true print false close default is closed)
# console = false

 

Log file storage path (the path written in the unslog.jar package):

windows at d://logs/application name/date/logfile

linux is in /opt/ci/logs/appname/date/log files

 

Fourth, log printing example

// General log printing

    logger.info("test start");

 

// Log rule ID (can be arranged uniformly)
     longbzId = 10000;
     // create log object
     UnsLogInfo uli = new UnsLogInfo(bzId);
     // set log information
     uli.put("userid", 12434);
     uli.put("userName", "name001");
     uli.put("startDt", new Date());
     // print business log
     logger.info (uli.toString ());

 // General log printing

 

     logger.info("test end");

5. Description

Log rule ID: It is the unique identifier of the business tracking point. Different business tracking points are different and can be compiled uniformly as needed.

Important indicator when performing business statistical analysis in the background (the log rule ID corresponds to one or more alarm rule IDs in the background, monitor the platform and perform statistical analysis)

 

Note: If the log adopts slf4j, it can be replaced by grayscale. Others need to modify the acquisition method of LoggerFactory by themselves (it is also very simple)

 

 

6. Practice

1. Import the unslog.jar package and add the following code to the pom.xml file:

 

<dependency>
     <groupId>com.uns.inf</groupId>
     <artifactId>unslog</artifactId>
     <version>1.0.0</version>
</dependency>

2. Use slf4j's Logger, because it can switch between log4j and logback at will, according to the logjar package you use, the code is as follows:

 

 

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final Logger log = LoggerFactory.getLogger(getClass());

 3. Write a public method for logging points, the code is as follows:

 

 

/**
	 * Hishi buried point
	 * @param curtran
	 * @param flag 1: success, 0: failure; bzId log rule ID
	 * @return
	 */
	public static String monitoring(Long bzId, Curtran curtran,String flag) {
	    // create log object
	    UnsLogInfo uli = new UnsLogInfo(bzId);
	    // set log information
	    if (Constant.TRUE.equals(flag)) {
	    	uli.setSuccess (1);
		} else {
			uli.setFailure (1);
		}
	    if (curtran != null) {
	    	uli.put("merchantId", curtran.getMerchantid());
	    	uli.put("terminalid", curtran.getTerminalid());
	    	uli.put("orderId", curtran.getTrannumber());
	    	uli.put("cardNo", curtran.getCard());
	    	uli.put("amount", curtran.getAmount());
		}
	    return uli.toString();
	}

 4. Application in the project, the code is as follows:

 

 

// Hishi buried point
log.info("Monitoring unspay start");
// print business log
log.info(Common.monitoring(20005L, curtran, Constant.TRUE));
log.info("Monitoring unspay end");

 

 

 5. If it is a WEB project, if you want to output the log of the console in the catalina.out file, you need to create a new configuration file unslog.properties

Add the following to the file:

#Project name (engineered projects are automatically obtained, no need to modify)  
app_name=${projectName}
# log level  
#log_level=info  
#log storage days  
#maxHistory=30  
#Whether the business buried point is output (true output false is closed, the default is closed)  
bizlog=true
#Console log close (true print false close default is closed)  
console=true

6. If you deploy to a Linux server, you need to confirm whether there is a pre-established directory /opt/ci/logs directory on the server

 

7. Points to note: logback is used for this log burying point, as log output

 

8. JAR package download (see attachment) 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326521156&siteId=291194637