2 * Copyright 2017 ZTE Corporation.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.openo.log.api;
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;
24 public class LogService {
26 private static final Logger LOGGER = LoggerFactory.getLogger(LogService.class.getName());
29 public static final String OPERLOG_SUCCESS = "log_success";
31 public static final String OPERLOG_ERROR = "log_fail";
34 public static final String OPERLOG_RANK_NORMAL = "operlog_rank_normal";
36 public static final String OPERLOG_RANK_NOTICE = "operlog_rank_notice";
38 public static final String OPERLOG_RANK_IMPORTANT = "operlog_rank_important";
40 public static final String OPERLOG_RANK_VERYIMPORTANT = " operlog_rank_veryimportant";
43 public static final String SYSLOG_RANK_INFORM = "syslog_rank_inform";
45 public static final String SYSLOG_RANK_NOTICE = "syslog_rank_notice";
48 public static final String SYSLOG_RANK_WARN = "syslog_rank_warn";
50 public static final String SYSLOG_RANK_ERROR = "syslog_rank_error";
53 public static final String SYSLOG_RANK_ALERT = "syslog_rank_alert";
56 public static final String SYSLOG_RANK_EMERG = "syslog_rank_emerg";
59 public static final String CONNECT_TYPE_WEB = "WEB";
61 public static final String CONNECT_TYPE_TELNET = "TELNET";
63 public static final String CONNECT_TYPE_SSH = "SSH";
65 public static final String CONNECT_TYPE_EM = "EM";
67 public static final short LOG_DISPLAY_NOT = 0;
69 public static final short LOG_DISPLAY = 1;
71 public static final int LOG_ROOT_LINK_ID = -1;
73 private static final int LOG_NO_LINK_ID = 0;
75 private static LogService recordLogHandler = null;
77 public static LogService getInstance() {
78 if (recordLogHandler == null) {
79 recordLogHandler = new LogService();
81 return recordLogHandler;
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)) {
91 LogIdTool.getRandomID(LogConst.CMD_LOG_FLAG, logMessage.getLogStartDate().getTime());
93 insertLogHandler.insertLog(logMessage, LogConst.AUDITLOG_OPERATION, LogConst.OPERLOG_TYPE);
95 return logMessage.getId();
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)) {
107 long id = LogIdTool.getRandomID(LogConst.SECRET_LOG_FLAG, logMessage.getLogDate().getTime());
108 logMessage.setId(id);
110 insertLogHandler.insertLog(logMessage, LogConst.AUDITLOG_SECURITY, LogConst.SERLOG_TYPE);
112 return logMessage.getId();
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)) {
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();
133 public static void main(String[] args)
135 LogService service = new LogService();
136 OperLogMessage logMessage = new OperLogMessage();
138 service.recordOperLog(logMessage );