2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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.
17 package oic.simulator.logger;
19 import java.util.Calendar;
20 import java.util.Date;
22 import oic.simulator.clientcontroller.Activator;
23 import oic.simulator.clientcontroller.utils.Constants;
25 import org.oic.simulator.ILogger;
28 * Class which provides a callback method to receive log from native layer.
30 public class LoggerCallback implements ILogger {
33 public void write(String time, int level, String message) {
34 if (null == time || level < 0 || null == message) {
38 Date date = parseTime(time);
42 Activator activator = Activator.getDefault();
43 if (null == activator) {
46 activator.getLogManager().log(level, date, message);
49 private Date parseTime(String time) {
51 String[] token = time.split("\\.");
54 if (token.length == Constants.PROPER_LOG_TIME_TOKEN_LENGTH) {
55 h = Integer.parseInt(token[0]);
56 m = Integer.parseInt(token[1]);
57 s = Integer.parseInt(token[2]);
60 calendar = Calendar.getInstance();
61 calendar.set(Calendar.HOUR_OF_DAY, h);
62 calendar.set(Calendar.MINUTE, m);
63 calendar.set(Calendar.SECOND, s);
65 date = calendar.getTime();
69 } catch (NumberFormatException nfe) {