Add logback to logstash test code
[vfc/nfvo/wfengine.git] / logging-sdk / src / main / java / org / openo / log / api / LogService.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.openo.log.api;
17
18 import org.openo.log.impl.InsertLogHandler;
19 import org.openo.log.impl.LogConst;
20 import org.openo.log.impl.LogIdTool;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class LogService {
25
26   private static final Logger LOGGER = LoggerFactory.getLogger(LogService.class.getName());
27
28
29   public static final String OPERLOG_SUCCESS = "log_success";
30
31   public static final String OPERLOG_ERROR = "log_fail";
32
33
34   public static final String OPERLOG_RANK_NORMAL = "operlog_rank_normal";
35
36   public static final String OPERLOG_RANK_NOTICE = "operlog_rank_notice";
37
38   public static final String OPERLOG_RANK_IMPORTANT = "operlog_rank_important";
39
40   public static final String OPERLOG_RANK_VERYIMPORTANT = " operlog_rank_veryimportant";
41
42
43   public static final String SYSLOG_RANK_INFORM = "syslog_rank_inform";
44
45   public static final String SYSLOG_RANK_NOTICE = "syslog_rank_notice";
46
47
48   public static final String SYSLOG_RANK_WARN = "syslog_rank_warn";
49
50   public static final String SYSLOG_RANK_ERROR = "syslog_rank_error";
51
52
53   public static final String SYSLOG_RANK_ALERT = "syslog_rank_alert";
54
55
56   public static final String SYSLOG_RANK_EMERG = "syslog_rank_emerg";
57
58
59   public static final String CONNECT_TYPE_WEB = "WEB";
60
61   public static final String CONNECT_TYPE_TELNET = "TELNET";
62
63   public static final String CONNECT_TYPE_SSH = "SSH";
64
65   public static final String CONNECT_TYPE_EM = "EM";
66
67   public static final short LOG_DISPLAY_NOT = 0;
68
69   public static final short LOG_DISPLAY = 1;
70
71   public static final int LOG_ROOT_LINK_ID = -1;
72
73   private static final int LOG_NO_LINK_ID = 0;
74
75   private static LogService recordLogHandler = null;
76
77   public static LogService getInstance() {
78     if (recordLogHandler == null) {
79       recordLogHandler = new LogService();
80     }
81     return recordLogHandler;
82   }
83
84   public long recordOperLog(OperLogMessage logMessage) {
85     // TODO Auto-generated method stub
86     LOGGER.info("receive a insert operLog message");
87     InsertLogHandler insertLogHandler = new InsertLogHandler();
88     if (insertLogHandler.checkCmdLog((OperLogMessage) logMessage)) {
89
90       long id =
91           LogIdTool.getRandomID(LogConst.CMD_LOG_FLAG, logMessage.getLogStartDate().getTime());
92       logMessage.setId(id);
93       insertLogHandler.insertLog(logMessage, LogConst.AUDITLOG_OPERATION, LogConst.OPERLOG_TYPE);
94
95       return logMessage.getId();
96     }
97
98     return 0;
99   }
100
101   public long recordSecLog(SecLogMessage logMessage) {
102     // TODO Auto-generated method stub
103     //LOGGER.info("receive a insert sec log message");
104     InsertLogHandler insertLogHandler = new InsertLogHandler();
105     if (insertLogHandler.checkSecLog((SecLogMessage) logMessage)) {
106
107       long id = LogIdTool.getRandomID(LogConst.SECRET_LOG_FLAG, logMessage.getLogDate().getTime());
108       logMessage.setId(id);
109
110       insertLogHandler.insertLog(logMessage, LogConst.AUDITLOG_SECURITY, LogConst.SERLOG_TYPE);
111
112       return logMessage.getId();
113     }
114     return 0;
115   }
116
117
118
119   public long recordSysLog(SysLogMessage logMessage) {
120     //LOGGER.info("receive a insert sys log message");
121     InsertLogHandler insertLogHandler = new InsertLogHandler();
122     if (insertLogHandler.checkSysLog((SysLogMessage) logMessage)) {
123
124       long id =
125           LogIdTool.getRandomID(LogConst.SYS_LOG_FLAG, logMessage.getLogStartDate().getTime());
126       logMessage.setId(id);
127       insertLogHandler.insertLog(logMessage, LogConst.AUDITLOG_SYSTEM, LogConst.SYSLOG_TYPE);
128       return logMessage.getId();
129     }
130     return 0;
131   }
132
133   public static void main(String[] args)
134   {
135     LogService service = new LogService();
136     OperLogMessage logMessage = new OperLogMessage();
137     
138     service.recordOperLog(logMessage );
139   }
140 }