Log problems at work, backup of existing logs, and log backup
The problem arises for some reason. The white point is what the customer needs and there is no way to do it. However, it also brings us a lot of trouble. I also hope that you can give me more ideas and thank you here.
The details are as follows:
1. You need to record the operator, operation time, and operations on the corresponding module.
2. raw data to be recorded (ps: column level) and post-Change Data
Problems:
1. Each method is relatively independent and there is no public interface
2. Different parameters have different order, different types, and different method names.
In view of the above, it is actually very easy to solve, mainly not afraid of trouble. Write an interface to call each module. This is a simple and effective method. However, there are too many modules and tedious tasks.
At present, I have found myself and my friends have added information and other information, which is roughly divided into two categories. There are four methods in total:
Category 1 (manual addition of execution functions is required for each related business ):
1. Log writing operation class. Add this interface call to relevant modules. This method is relatively simple. If you have this part of code at the beginning, it will be better solved. This method is needless to say, just like the normal interface.
2. Using message-oriented middleware, implementation 2 and 1 are similar, and jms needs to be called each time. However, performance 2 is better than performance 1.
3. Use log4j for logging. For details, see http://blog.csdn.net/ziruobing/article/details/3919501,logback.
The second type (using Aop, interceptor, etc ):
1. Aop. The implementation idea @ BussAnnotation annotation can mark the relevant business information (ps: add, delete, modify, and other operations, as well as the information of the module. The parameter ProceedingJoinPoint In aop can obtain the parameter object.
@ Component ("userManager ")
Public class UserManagerApplogicImpl implements UserManagerApplogic {
@ BussAnnotation (moduleName = "Personnel Management", option = "Add User ")
Public void addUser (String name ){
System. out. println ("add a User! Name is "+ name );
}
}
@ Aspect
@ Component
Public class LogInterceptor {
@ Pointcut ("execution (public * com. mlliud... *. addUser (..))")
Public void aApplogic (){}
@ Around (value = "aApplogic () & @ annotation (annotation) & args (object,...)", argNames = "annotation, object ")
Public Object interceptorApplogic (ProceedingJoinPoint pj, BussAnnotation annotation, Object object Object) throws Throwable {
System. out. println ("moduleName:" + annotation. moduleName ());
System. out. println ("option:" + annotation. option ());
Pj. proceed ();
Return object;
}
}
2. Interceptor. This simple log is fine. Check it for other projects. I am so stupid that I only want to record some logs based on the access link.
It seems that the above problems are analyzed for our project. Conclusion:
1. The first type should be considered in the initial stage of the project or have relevant requirements. The Code involved in each module should be changed and can be manually added. If the project structure is complex or the amount of code is large, I think it is very difficult .....
2. Although the @ BussAnnotation annotation in the second type of aop can mark some key information, we should record the relevant change information of the entire vo after all. Because there were no special specifications for the parameters at the time and there was no planning for the types, the parameters obtained by ProceedingJoinPoint were not regularly searchable, for example: addUser (User u, int a), updateUser (User u, String x) in this way, I can obtain the first parameter and store it in the database. Other things you know ....
3. Interceptor ....
I hope you can give me some ideas and find a better way to write this article ....
We also hope that the following group will be publicized: 189770377. We hope that you will be able to stay and put forward more good ideas. I also hope that my new students will be able to get a good idea here.