]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.platform.ui/src/org/simantics/platform/ui/internal/ConsoleAppender.java
Fixed Simantics Console activation and formatted message output
[simantics/platform.git] / bundles / org.simantics.platform.ui / src / org / simantics / platform / ui / internal / ConsoleAppender.java
1 /*******************************************************************************
2  * Copyright (c) 2019 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.platform.ui.internal;
13
14 import java.text.DateFormat;
15 import java.text.SimpleDateFormat;
16 import java.util.Date;
17 import java.util.TimeZone;
18
19 import org.simantics.platform.ui.SimanticsConsole;
20
21 import ch.qos.logback.classic.spi.ILoggingEvent;
22 import ch.qos.logback.core.AppenderBase;
23
24 public class ConsoleAppender extends AppenderBase<ILoggingEvent> {
25
26     final private SimanticsConsole console;
27
28     final private DateFormat formatter;
29
30     ConsoleAppender(SimanticsConsole console) {
31         assert(console != null);
32         this.console = console;
33         formatter = new SimpleDateFormat("dd.LL.yyyy HH:mm:ss.SSS");
34         formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
35     }
36
37     @Override
38     protected void append(ILoggingEvent e) {
39         StringBuilder b = new StringBuilder();
40         b.append('[');
41         b.append(formatter.format(new Date(e.getTimeStamp())));
42         b.append("]: ");
43         b.append(e.getFormattedMessage());
44         console.write(b.toString());
45     }
46     
47 }