-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from alechenninger/verbose
Fixes #73: Add verbose flag
- Loading branch information
Showing
9 changed files
with
244 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
bin/src/io/github/alechenninger/monarch/logging/ImmediateFlushStreamHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* monarch - A tool for managing hierarchical data. | ||
* Copyright (C) 2017 Alec Henninger | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.github.alechenninger.monarch.logging; | ||
|
||
import java.io.OutputStream; | ||
import java.util.logging.Formatter; | ||
import java.util.logging.LogRecord; | ||
import java.util.logging.StreamHandler; | ||
|
||
public class ImmediateFlushStreamHandler extends StreamHandler { | ||
public ImmediateFlushStreamHandler(OutputStream out, Formatter formatter) { | ||
super(out, formatter); | ||
} | ||
|
||
@Override | ||
public synchronized void publish(LogRecord record) { | ||
super.publish(record); | ||
flush(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
bin/src/io/github/alechenninger/monarch/logging/Logging.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* monarch - A tool for managing hierarchical data. | ||
* Copyright (C) 2017 Alec Henninger | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.github.alechenninger.monarch.logging; | ||
|
||
import java.io.OutputStream; | ||
import java.util.logging.Handler; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public abstract class Logging { | ||
private static Logger rootLogger = Logger.getLogger(""); | ||
|
||
/** | ||
* Configures warnings and above to {@code stderr}, everything else to {@code stdout}. For either | ||
* output stream, only log record at or above {@code logLevel} are written. | ||
*/ | ||
public static void outputTo(OutputStream stdout, OutputStream stderr) { | ||
for (Handler handler : rootLogger.getHandlers()) { | ||
rootLogger.removeHandler(handler); | ||
} | ||
|
||
rootLogger.addHandler(new MonarchStdoutLogHandler(stdout)); | ||
rootLogger.addHandler(new MonarchStderrLogHandler(stderr)); | ||
} | ||
|
||
public static void setLevel(Level logLevel) { | ||
rootLogger.setLevel(logLevel); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
bin/src/io/github/alechenninger/monarch/logging/MonarchLogFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* monarch - A tool for managing hierarchical data. | ||
* Copyright (C) 2017 Alec Henninger | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.github.alechenninger.monarch.logging; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import java.util.logging.Formatter; | ||
import java.util.logging.Level; | ||
import java.util.logging.LogRecord; | ||
|
||
public class MonarchLogFormatter extends Formatter { | ||
@Override | ||
public String format(LogRecord record) { | ||
String levelPrefix = record.getLevel().intValue() >= Level.WARNING.intValue() | ||
? record.getLevel().getLocalizedName() + ": " | ||
: ""; | ||
Throwable thrown = record.getThrown(); | ||
String stackTrace = ""; | ||
if (thrown != null) { | ||
StringWriter writer = new StringWriter(); | ||
thrown.printStackTrace(new PrintWriter(writer)); | ||
stackTrace = writer.toString(); | ||
} | ||
return levelPrefix + record.getMessage() + '\n' + stackTrace; | ||
} | ||
} |
Oops, something went wrong.