Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move Locale-Initialization to Run-Action
Also configure Logger not before Run-Action and log it when we change
the locale based on LC_ALL environment variable
  • Loading branch information
pesse committed Dec 10, 2019
commit eca111507a2760d64941e33b56d7d1da4c53374e
3 changes: 0 additions & 3 deletions src/main/java/org/utplsql/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public static void main(String[] args) {

static int runPicocliWithExitCode(String[] args) {

LoggerConfiguration.configure(LoggerConfiguration.ConfigLevel.NONE);
LocaleInitializer.initLocale();

CommandLine commandLine = new CommandLine(UtplsqlPicocliCommand.class);
commandLine.setTrimQuotes(true);

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/utplsql/cli/LocaleInitializer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.utplsql.cli;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.utplsql.api.EnvironmentVariableUtil;

import java.util.Locale;
Expand All @@ -18,6 +20,8 @@
*/
class LocaleInitializer {

private static final Logger logger = LoggerFactory.getLogger(RunAction.class);

private static final Pattern REGEX_LOCALE = Pattern.compile("^([a-zA-Z]+)[_-]([a-zA-Z]+)"); // We only need the very first part and are pretty forgiving in parsing

/**
Expand All @@ -27,7 +31,10 @@ static void initLocale() {

boolean localeChanged = setDefaultLocale(EnvironmentVariableUtil.getEnvValue("LC_ALL"));
if (!localeChanged) {
setDefaultLocale(EnvironmentVariableUtil.getEnvValue("LANG"));
localeChanged = setDefaultLocale(EnvironmentVariableUtil.getEnvValue("LANG"));
}
if ( !localeChanged ) {
logger.debug("Java Locale not changed from LC_ALL or LANG environment variable");
}
}

Expand All @@ -54,6 +61,7 @@ private static boolean setDefaultLocale(String localeString) {
Locale l = new Locale.Builder().setLanguageTag(sb.toString()).build();
if (l != null) {
Locale.setDefault(l);
logger.debug("Java Locale changed to {}", l);
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/utplsql/cli/RunAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public RunAction(RunCommandConfig config) {

void init() {
LoggerConfiguration.configure(config.getLogConfigLevel());
LocaleInitializer.initLocale();
}

public RunCommandConfig getConfig() {
Expand Down