Implementation principle of system operation log

Source: Internet
Author: User
Define action Log entities
public class Systemoperationlog extends BaseEntity {/** * */private static final long Serialversionu

    ID = 8596392701331679567L;

    /** * operator * */private String operator;

    /** * Log type */private String logtype;

    /** * Create time */private Date createtime;

    /** * Log Details */private String logdetail;
    Public String Getoperator () {return operator;
    } public void Setoperator (String operator) {this.operator = operator;
    } public String Getlogtype () {return logtype;
    } public void Setlogtype (String logtype) {this.logtype = LogType;
        Public Date Getcreatetime () {if (createtime!=null) {return (Date) Createtime.clone ();
    } return null; public void Setcreatetime (date createtime) {if (createtime!=null) {this.createtime = (date) creat
        Etime.clone (); }else{This.createtIME = null;
    }} public String Getlogdetail () {return logdetail;
    } public void Setlogdetail (String logdetail) {this.logdetail = Logdetail; }   
}
defining a constant class for log formats and categories
Public interface Logmessageconstant {//******************begin**** operation log corresponds to type *******************************/**
    * Customer Open */public static final String Logtype_customer_open = "0";
    /** * Service Open */public static final String Logtype_service_open = "1";

    /** * Order Relationship Change */public static final String Logtype_subscriber_order_change = "2";

    /** * Account Recharge */public static final String Logtype_account_recharge = "3";

    /** * Product Order */public static final String logtype_order_product = "4";


    /** * User logoff */public static final String logtype_user_termination = "5"; Operation Log Details ***************************/** * Service Opening details */public static final St
    Ring Msg_service_open = "operator {0} customer {1} service";
    /** * Customer Opening Details */public static final String msg_customer_open= "operator {0} open account for customer {1}"; /** * Account Recharge * * public static final String MSg_account_recharge= "operator {0} to recharge {2} yuan for customer {1}";

    /** * User Subscription Package */public static final String msg_order_main= "operator {0} order {2} products for customer {1}";

    /** * User Modified Subscription Package */public static final String msg_order_update= "operator {0} modify order {2} product for customer {1}";

    /** * User */public static final String msg_order_cancel= "operator {0} for customer {1} Cancel product {2} order";   
/** * User logoff */public static final String msg_user_termination= "operator {0} sign out {2} user for customer {1}"; }
Business Interface Methods
/**
    * @Title: Listoperlog 
    * @Description: Get operation log paging information according to conditions
    * @param @param pageparam
    * @param @param par AMS
    * @param @return
    * @return pagebean<systemoperationlog> */public
    pagebean< Systemoperationlog> Listoperlog (Pageparam pageparam,map<string,object> params);
    /**
    * @Title: Savelog 
    * @Description: Save system Operation Log
    * @param @param log
    * @param @param params
    * @par Am @return
    * @return Boolean
     *
    /public boolean saveoperationlog (Systemoperationlog log, Map<integer ,string> params);
Business Interface Implementation
public boolean saveoperationlog (Systemoperationlog log, map<integer,string> params) {
        String logdetail = Log.getlogdetail ();

        if (Stringutil.isnotnull (Logdetail)) {for
            (int i=0;i<params.size (); i++) {
                String value = Params.get ( Integer.valueof (i));
                Logdetail = Logdetail.replace ("{" +i+ "}", value);
            }
            Log.setlogdetail (logdetail);
            Insert (log);
            return true;
        }
        return false;
    }
How to use
map<integer,string> pm = new hashmap<> ();
Pm.put (0,customerinfo.getcreateoperator ());
Pm.put (1,customerinfo.getcustomername ());
Systemoperationlog log = new Systemoperationlog ();
Log.setlogtype (Logmessageconstant.logtype_customer_open);
        Log.setcreatetime (UTCTIMEUTIL.GETLOCALTIMEFROMUTC (Sdf.format (Customerinfo.getcreatetime ()));
Log.setoperator (Customerinfo.getcreateoperator ());
Log.setlogdetail (Logmessageconstant.msg_customer_open);

Systemoperationlogservice.saveoperationlog (log, PM);
Usage Summary

For the operation log this data can be saved in MySQL, or can be saved in the MongoDB database, because this kind of business only need to do save and query function, so it is generally stored in the MongoDB database. As long as the stored procedure for the operation log is developed, when there is a new type of operation log, only the corresponding log type and the format definition of the detail information need to be added. Example: operator {0} logs off {2} user for customer {1}

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.