mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Add additional log verbosity levels
This commit is contained in:
parent
e3fcc9b3ba
commit
1e8c5eb522
2 changed files with 15 additions and 14 deletions
|
@ -64,8 +64,8 @@ public class App {
|
||||||
|
|
||||||
parser.addArgument("-v", "--version").help("Show package version.").action(Arguments.version());
|
parser.addArgument("-v", "--version").help("Show package version.").action(Arguments.version());
|
||||||
parser.addArgument("--verbose")
|
parser.addArgument("--verbose")
|
||||||
.help("Raise log level and include lib signal logs.")
|
.help("Raise log level and include lib signal logs. Specify multiple times for even more logs.")
|
||||||
.action(Arguments.storeTrue());
|
.action(Arguments.count());
|
||||||
parser.addArgument("-c", "--config")
|
parser.addArgument("-c", "--config")
|
||||||
.help("Set the path, where to store the config (Default: $XDG_DATA_HOME/signal-cli , $HOME/.local/share/signal-cli).");
|
.help("Set the path, where to store the config (Default: $XDG_DATA_HOME/signal-cli , $HOME/.local/share/signal-cli).");
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,8 @@ public class Main {
|
||||||
installSecurityProviderWorkaround();
|
installSecurityProviderWorkaround();
|
||||||
|
|
||||||
// Configuring the logger needs to happen before any logger is initialized
|
// Configuring the logger needs to happen before any logger is initialized
|
||||||
final var isVerbose = isVerbose(args);
|
final var verboseLevel = getVerboseLevel(args);
|
||||||
configureLogging(isVerbose);
|
configureLogging(verboseLevel);
|
||||||
|
|
||||||
var parser = App.buildArgumentParser();
|
var parser = App.buildArgumentParser();
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public class Main {
|
||||||
new App(ns).init();
|
new App(ns).init();
|
||||||
} catch (CommandException e) {
|
} catch (CommandException e) {
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
if (isVerbose && e.getCause() != null) {
|
if (verboseLevel > 0 && e.getCause() != null) {
|
||||||
e.getCause().printStackTrace();
|
e.getCause().printStackTrace();
|
||||||
}
|
}
|
||||||
status = getStatusForError(e);
|
status = getStatusForError(e);
|
||||||
|
@ -70,37 +70,38 @@ public class Main {
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isVerbose(String[] args) {
|
private static int getVerboseLevel(String[] args) {
|
||||||
var parser = ArgumentParsers.newFor("signal-cli").build().defaultHelp(false);
|
var parser = ArgumentParsers.newFor("signal-cli").build().defaultHelp(false);
|
||||||
parser.addArgument("--verbose").action(Arguments.storeTrue());
|
parser.addArgument("--verbose").action(Arguments.count());
|
||||||
|
|
||||||
Namespace ns;
|
Namespace ns;
|
||||||
try {
|
try {
|
||||||
ns = parser.parseKnownArgs(args, null);
|
ns = parser.parseKnownArgs(args, null);
|
||||||
} catch (ArgumentParserException e) {
|
} catch (ArgumentParserException e) {
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Boolean.TRUE.equals(ns.getBoolean("verbose"));
|
return ns.getInt("verbose");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void configureLogging(final boolean verbose) {
|
private static void configureLogging(final int verboseLevel) {
|
||||||
if (verbose) {
|
final var defaultLogLevel = verboseLevel > 1 ? "trace" : verboseLevel > 0 ? "debug" : "info";
|
||||||
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug");
|
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", defaultLogLevel);
|
||||||
|
if (verboseLevel > 0) {
|
||||||
System.setProperty("org.slf4j.simpleLogger.showThreadName", "true");
|
System.setProperty("org.slf4j.simpleLogger.showThreadName", "true");
|
||||||
System.setProperty("org.slf4j.simpleLogger.showShortLogName", "false");
|
System.setProperty("org.slf4j.simpleLogger.showShortLogName", "false");
|
||||||
System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
|
System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
|
||||||
System.setProperty("org.slf4j.simpleLogger.dateTimeFormat", "yyyy-MM-dd'T'HH:mm:ss.SSSXX");
|
System.setProperty("org.slf4j.simpleLogger.dateTimeFormat", "yyyy-MM-dd'T'HH:mm:ss.SSSXX");
|
||||||
|
java.util.logging.Logger.getLogger("")
|
||||||
|
.setLevel(verboseLevel > 2 ? java.util.logging.Level.FINEST : java.util.logging.Level.INFO);
|
||||||
Manager.initLogger();
|
Manager.initLogger();
|
||||||
} else {
|
} else {
|
||||||
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
|
|
||||||
System.setProperty("org.slf4j.simpleLogger.showThreadName", "false");
|
System.setProperty("org.slf4j.simpleLogger.showThreadName", "false");
|
||||||
System.setProperty("org.slf4j.simpleLogger.showShortLogName", "true");
|
System.setProperty("org.slf4j.simpleLogger.showShortLogName", "true");
|
||||||
System.setProperty("org.slf4j.simpleLogger.showDateTime", "false");
|
System.setProperty("org.slf4j.simpleLogger.showDateTime", "false");
|
||||||
}
|
}
|
||||||
SLF4JBridgeHandler.removeHandlersForRootLogger();
|
SLF4JBridgeHandler.removeHandlersForRootLogger();
|
||||||
SLF4JBridgeHandler.install();
|
SLF4JBridgeHandler.install();
|
||||||
// java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.FINEST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getStatusForError(final CommandException e) {
|
private static int getStatusForError(final CommandException e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue