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.impl;
18 import java.util.Date;
19 import java.util.Random;
23 public class LogIdTool {
24 private static Random cmdRand = new Random();
26 private static Random sysRand = new Random();
28 private static Random secRand = new Random();
34 public static long getRandomID(int logType, long startDate) {
35 String strCtime = "" + startDate;
36 if (strCtime.length() > 13) {
37 strCtime = strCtime.substring(strCtime.length() - 13);
40 if (logType == LogConst.CMD_LOG_FLAG) {
41 seed1 = cmdRand.nextInt(100000);
42 } else if (logType == LogConst.SYS_LOG_FLAG) {
43 seed1 = sysRand.nextInt(100000);
44 } else if (logType == LogConst.SECRET_LOG_FLAG) {
45 seed1 = secRand.nextInt(100000);
49 String seed2 = "" + seed1;
50 int shouldFillLen = 5 - seed2.length();
51 for (int i = 0; i < shouldFillLen; i++) {
54 return Long.parseLong(strCtime + seed2);
57 public static long transTimeCond2ID(Date time, boolean isStart) {
58 long timeLong = time.getTime();
60 timeLong = timeLong * 100000;
62 timeLong = timeLong * 100000 + 99999;