001/* 002 * (C) Copyright 2011-2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Julien Carsique 018 * 019 */ 020 021package org.nuxeo.launcher.gui.logs; 022 023import java.awt.Color; 024import java.util.Observable; 025import java.util.Observer; 026 027import org.nuxeo.launcher.gui.ColoredTextPane; 028 029/** 030 * @author jcarsique 031 * @since 5.4.2 032 */ 033public class LogsHandler implements Observer { 034 035 private ColoredTextPane textArea; 036 037 public LogsHandler(ColoredTextPane textArea) { 038 this.textArea = textArea; 039 } 040 041 @Override 042 public void update(Observable obj, Object arg) { 043 if (arg instanceof String) { 044 notifyLogsView((String) arg); 045 } 046 } 047 048 /** 049 * @param logLine Line read from log file being sent to view 050 */ 051 public void notifyLogsView(String logLine) { 052 Color color; 053 String[] split = logLine.split(" ", 4); 054 if (split.length < 3) { 055 color = new Color(234, 234, 234); 056 } else if ("INFO".equals(split[2])) { 057 color = new Color(234, 234, 234); 058 } else if ("DEBUG".equals(split[2])) { 059 color = new Color(108, 183, 242); 060 } else if ("WARN".equals(split[2])) { 061 color = new Color(234, 138, 2); 062 } else if ("ERROR".equals(split[2])) { 063 color = new Color(245, 0, 63); 064 } else { 065 color = new Color(234, 234, 234); 066 } 067 textArea.append(logLine, color); 068 } 069}