mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
Allow redirect logs to console
This commit is contained in:
parent
ff49809d77
commit
63f153c0c2
@ -57,11 +57,15 @@ import processing.app.tools.MenuScroller;
|
||||
import processing.app.tools.ZipDeflater;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -137,6 +141,8 @@ public class Base {
|
||||
|
||||
BaseNoGui.initLogger();
|
||||
|
||||
initLogger();
|
||||
|
||||
BaseNoGui.notifier = new GUIUserNotifier();
|
||||
|
||||
initPlatform();
|
||||
@ -215,6 +221,34 @@ public class Base {
|
||||
INSTANCE = new Base(args);
|
||||
}
|
||||
|
||||
|
||||
static public void initLogger() {
|
||||
Handler consoleHandler = new ConsoleLogger();
|
||||
consoleHandler.setLevel(Level.ALL);
|
||||
consoleHandler.setFormatter(new LogFormatter("%1$tl:%1$tM:%1$tS [%4$7s] %2$s: %5$s%n"));
|
||||
|
||||
Logger globalLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
|
||||
globalLogger.setLevel(consoleHandler.getLevel());
|
||||
|
||||
// Remove default
|
||||
Handler[] handlers = globalLogger.getHandlers();
|
||||
for(Handler handler : handlers) {
|
||||
globalLogger.removeHandler(handler);
|
||||
}
|
||||
Logger root = Logger.getLogger("");
|
||||
handlers = root.getHandlers();
|
||||
for(Handler handler : handlers) {
|
||||
root.removeHandler(handler);
|
||||
}
|
||||
|
||||
globalLogger.addHandler(consoleHandler);
|
||||
|
||||
Logger.getLogger("cc.arduino.packages.autocomplete").setParent(globalLogger);
|
||||
Logger.getLogger("br.com.criativasoft.cpluslibparser").setParent(globalLogger);
|
||||
Logger.getLogger(Base.class.getPackage().getName()).setParent(globalLogger);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static protected void setCommandLine() {
|
||||
commandLine = true;
|
||||
@ -2098,6 +2132,14 @@ public class Base {
|
||||
// don't use the low-res icon on Mac OS X; the window should
|
||||
// already have the right icon from the .app file.
|
||||
if (OSUtils.isMacOS()) return;
|
||||
|
||||
// don't use the low-res icon on Linux
|
||||
if (OSUtils.isLinux()){
|
||||
String current = System.getProperty("user.dir");
|
||||
Image image = Toolkit.getDefaultToolkit().createImage(current + "/lib/arduino.png");
|
||||
frame.setIconImage(image);
|
||||
return;
|
||||
}
|
||||
|
||||
Image image = Toolkit.getDefaultToolkit().createImage(PApplet.ICON_IMAGE);
|
||||
frame.setIconImage(image);
|
||||
@ -2152,7 +2194,12 @@ public class Base {
|
||||
File referenceFile = new File(referenceFolder, filename);
|
||||
if (!referenceFile.exists())
|
||||
referenceFile = new File(referenceFolder, filename + ".html");
|
||||
openURL(referenceFile.getAbsolutePath());
|
||||
|
||||
if(referenceFile.exists()){
|
||||
openURL(referenceFile.getAbsolutePath());
|
||||
}else{
|
||||
showWarning(_("Problem Opening URL"), I18n.format(_("Could not open the URL\n{0}"), referenceFile), null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void showEdisonGettingStarted() {
|
||||
|
30
app/src/processing/app/helpers/ConsoleLogger.java
Normal file
30
app/src/processing/app/helpers/ConsoleLogger.java
Normal file
@ -0,0 +1,30 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.StreamHandler;
|
||||
|
||||
public class ConsoleLogger extends StreamHandler {
|
||||
|
||||
public ConsoleLogger() {
|
||||
setOutputStream(new PrintStream(new FileOutputStream(FileDescriptor.out)));
|
||||
}
|
||||
|
||||
|
||||
public void publish(LogRecord record) {
|
||||
super.publish(record);
|
||||
flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override <tt>StreamHandler.close</tt> to do a flush but not
|
||||
* to close the output stream. That is, we do <b>not</b>
|
||||
* close <tt>FileDescriptor.out</tt>.
|
||||
*/
|
||||
public void close() {
|
||||
flush();
|
||||
}
|
||||
|
||||
}
|
49
app/src/processing/app/helpers/LogFormatter.java
Normal file
49
app/src/processing/app/helpers/LogFormatter.java
Normal file
@ -0,0 +1,49 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class LogFormatter extends Formatter {
|
||||
|
||||
public String format;
|
||||
private final Date dat = new Date();
|
||||
|
||||
public LogFormatter(String logformat) {
|
||||
format = logformat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
dat.setTime(record.getMillis());
|
||||
String source;
|
||||
if (record.getSourceClassName() != null) {
|
||||
source = record.getSourceClassName().substring(record.getSourceClassName().lastIndexOf('.') + 1);
|
||||
if (record.getSourceMethodName() != null) {
|
||||
source += "." + record.getSourceMethodName();
|
||||
}
|
||||
} else {
|
||||
source = record.getLoggerName();
|
||||
}
|
||||
String message = formatMessage(record);
|
||||
String throwable = "";
|
||||
if (record.getThrown() != null) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
pw.println();
|
||||
record.getThrown().printStackTrace(pw);
|
||||
pw.close();
|
||||
throwable = sw.toString();
|
||||
}
|
||||
return String.format(format,
|
||||
dat,
|
||||
source,
|
||||
record.getLoggerName(),
|
||||
record.getLevel(),
|
||||
message,
|
||||
throwable);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user