diff --git a/java_console/logging/src/main/java/com/rusefi/util/LazyFileImpl.java b/java_console/logging/src/main/java/com/rusefi/util/LazyFileImpl.java index 6d871daaa0..5d7f138668 100644 --- a/java_console/logging/src/main/java/com/rusefi/util/LazyFileImpl.java +++ b/java_console/logging/src/main/java/com/rusefi/util/LazyFileImpl.java @@ -1,15 +1,20 @@ package com.rusefi.util; +import com.devexperts.logging.Logging; + import java.io.*; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Scanner; import java.util.regex.Pattern; +import static com.devexperts.logging.Logging.getLogging; + /** * This file would override file content only of content has changed, disregarding the magic tag line. */ public class LazyFileImpl implements LazyFile { + private static final Logging log = getLogging(LazyFileImpl.class); private final String filename; @@ -44,15 +49,15 @@ public class LazyFileImpl implements LazyFile { String newContent = unifySpaces(contentWithoutTag.toString()); if (fileContent.equals(newContent)) { - SystemOut.println(getClass().getSimpleName() + ": Not updating " + filename + " since looks to be the same content, new content size=" + contentWithoutTag.length()); + log.info(getClass().getSimpleName() + ": Not updating " + filename + " since looks to be the same content, new content size=" + contentWithoutTag.length()); return; } for (int i = 0; i < Math.min(fileContent.length(), newContent.length()); i++) { if (fileContent.charAt(i) != newContent.charAt(i)) { - SystemOut.println(getClass().getSimpleName() + " " + filename + ": Not same at " + i); + log.info(getClass().getSimpleName() + " " + filename + ": Not same at " + i); if (i > 15 && i < fileContent.length() - 6 && i < newContent.length() - 6) { - SystemOut.println("file " + fileContent.substring(i - 15, i + 5)); - SystemOut.println("newContent " + newContent.substring(i - 15, i + 5)); + log.info("file " + fileContent.substring(i - 15, i + 5)); + log.info("newContent " + newContent.substring(i - 15, i + 5)); } break; } @@ -67,7 +72,7 @@ public class LazyFileImpl implements LazyFile { if (LazyFile.TEST.equals(filename)) return ""; if (!new File(filename).exists()) { - SystemOut.println(filename + " does not exist considering empty current content"); + log.info(filename + " does not exist considering empty current content"); return ""; } Scanner in = new Scanner(Paths.get(filename), IoUtils.CHARSET.name()); diff --git a/java_console/logging/src/main/java/com/rusefi/util/SystemOut.java b/java_console/logging/src/main/java/com/rusefi/util/SystemOut.java deleted file mode 100644 index ed54522a5e..0000000000 --- a/java_console/logging/src/main/java/com/rusefi/util/SystemOut.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.rusefi.util; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; - -/** - * Utility class which writes same line both to stdout and file - */ -//@ThreadSafe -public class SystemOut { - private static final String LOG = ".log"; - private static PrintWriter logFile; - - public static void println(String line) { - System.out.println(line); - try { - openFileIfNeeded(); - logFile.write(line + "\r\n"); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - private static synchronized void openFileIfNeeded() throws IOException { - if (logFile != null) - return; - String fileName = System.getProperty("SystemOut.name", "rusefi_tool") + LOG; - System.out.println("Opening " + fileName); - File parentFile = new File(fileName).getParentFile(); - if (parentFile != null) - parentFile.mkdirs(); - logFile = new PrintWriter(new FileWriter(fileName, true)); - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { - @Override - public void run() { - close(); - System.out.println("SystemOut Hook done for " + fileName); - } - })); - } - - @SuppressWarnings("ThrowablePrintedToSystemOut") - public static void println(Throwable param) { - System.out.println(param); - try { - openFileIfNeeded(); - param.printStackTrace(logFile); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - public static void println(Object object) { - println(object == null ? "(null)" : object.toString()); - } - - public synchronized static void close() { - if (logFile != null) { - logFile.close(); - } - logFile = null; - } -} diff --git a/java_console/shared_io/src/main/java/com/rusefi/core/rusEFIVersion.java b/java_console/shared_io/src/main/java/com/rusefi/core/rusEFIVersion.java index bcdca66a93..49717b9922 100644 --- a/java_console/shared_io/src/main/java/com/rusefi/core/rusEFIVersion.java +++ b/java_console/shared_io/src/main/java/com/rusefi/core/rusEFIVersion.java @@ -9,7 +9,7 @@ public interface rusEFIVersion { /** * @see com.rusefi.autoupdate.Autoupdate#VERSION */ - int CONSOLE_VERSION = 20240817; + int CONSOLE_VERSION = 20240819; AtomicReference firmwareVersion = new AtomicReference<>("N/A"); static long classBuildTimeMillis() { diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java b/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java index f3504164b3..1b9aa3e2a0 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java @@ -1,11 +1,11 @@ package com.rusefi; +import com.devexperts.logging.Logging; import com.rusefi.newparse.DefinitionsState; import com.rusefi.output.*; import com.rusefi.pinout.PinoutLogic; import com.rusefi.trigger.TriggerWheelTSLogic; import com.rusefi.util.LazyFile; -import com.rusefi.util.SystemOut; import java.io.*; import java.nio.file.Files; @@ -19,6 +19,7 @@ import java.util.*; * @see ConfigurationConsumer */ public class ConfigDefinition { + private final static Logging log = Logging.getLogging(ConfigDefinition.class); public static final String SIGNATURE_HASH = "SIGNATURE_HASH"; private static final String KEY_DEFINITION = "-definition"; @@ -42,7 +43,7 @@ public class ConfigDefinition { options.addAll(Arrays.asList(args)); String[] totalArgs = options.toArray(new String[0]); if (totalArgs.length < 2) { - SystemOut.println("Please specify\r\n" + log.error("Please specify\r\n" + KEY_DEFINITION + " x\r\n" + KEY_TS_TEMPLATE + " x\r\n" + KEY_C_DESTINATION + " x\r\n" @@ -52,16 +53,14 @@ public class ConfigDefinition { } doJob(totalArgs, new ReaderStateImpl()); } catch (Throwable e) { - SystemOut.println(e); + log.error("unexpected", e); e.printStackTrace(); System.exit(-1); - } finally { - SystemOut.close(); } } public static void doJob(String[] args, ReaderStateImpl state) throws IOException { - SystemOut.println(ConfigDefinition.class + " Invoked with " + Arrays.toString(args)); + log.info(ConfigDefinition.class + " Invoked with " + Arrays.toString(args)); String tsInputFileFolder = null; @@ -168,7 +167,7 @@ public class ConfigDefinition { state.addInputFile(TSProjectConsumer.getTsFileInputName(tsInputFileFolder)); } - SystemOut.println(state.getEnumsReader().getEnums().size() + " total enumsReader"); + log.info(state.getEnumsReader().getEnums().size() + " total enumsReader"); // Add the variable for the config signature FirmwareVersion uniqueId = new FirmwareVersion(IoUtil2.getCrc32(state.getInputFiles())); diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/ExtraUtil.java b/java_tools/configuration_definition/src/main/java/com/rusefi/ExtraUtil.java index 9ba06f8d32..9628c62883 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/ExtraUtil.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/ExtraUtil.java @@ -1,15 +1,16 @@ package com.rusefi; +import com.devexperts.logging.Logging; import com.rusefi.newparse.DefinitionsState; import com.rusefi.newparse.parsing.Definition; -import com.rusefi.util.SystemOut; import java.io.IOException; public class ExtraUtil { + private final static Logging log = Logging.getLogging(ExtraUtil.class); static void handleFiringOrder(String firingEnumFileName, VariableRegistry variableRegistry, DefinitionsState parseState) throws IOException { if (firingEnumFileName != null) { - SystemOut.println("Reading firing from " + firingEnumFileName); + log.info("Reading firing from " + firingEnumFileName); String result = FiringOrderTSLogic.invoke(firingEnumFileName); parseState.addDefinition(variableRegistry, "FIRINGORDER", result, Definition.OverwritePolicy.NotAllowed); } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/IoUtil2.java b/java_tools/configuration_definition/src/main/java/com/rusefi/IoUtil2.java index 463c80c98e..696448463a 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/IoUtil2.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/IoUtil2.java @@ -1,6 +1,6 @@ package com.rusefi; -import com.rusefi.util.SystemOut; +import com.devexperts.logging.Logging; import java.io.BufferedReader; import java.io.File; @@ -11,6 +11,7 @@ import java.util.List; import java.util.zip.CRC32; public class IoUtil2 { + private final static Logging log = Logging.getLogging(IoUtil2.class); static String readFile(String fileName) { String line; StringBuilder stringBuilder = new StringBuilder(); @@ -50,10 +51,10 @@ public class IoUtil2 { long crc32 = 0; for (String fileName : inputFileNames) { long c = getCrc32(fileName) & 0xffffffffL; - SystemOut.println("CRC32 from " + fileName + " = " + c); + log.info("CRC32 from " + fileName + " = " + c); crc32 ^= c; } - SystemOut.println("CRC32 from all input files = " + crc32); + log.info("CRC32 from all input files = " + crc32); return crc32; } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/SignatureConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/SignatureConsumer.java index 2395f8b96e..28ac7e8936 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/SignatureConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/SignatureConsumer.java @@ -1,9 +1,9 @@ package com.rusefi.output; +import com.devexperts.logging.Logging; import com.rusefi.*; import com.rusefi.newparse.DefinitionsState; import com.rusefi.newparse.parsing.Definition; -import com.rusefi.util.SystemOut; import java.io.IOException; @@ -13,11 +13,12 @@ import java.io.IOException; * See also gen_signature.sh */ public class SignatureConsumer implements ConfigurationConsumer { + private final static Logging log = Logging.getLogging(SignatureConsumer.class); private final String destHeader; private final VariableRegistry registry; public SignatureConsumer(String destHeader, VariableRegistry registry) { - SystemOut.println("Writing Signature header to " + destHeader); + log.info("Writing Signature header to " + destHeader); this.destHeader = destHeader; this.registry = registry; } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/TSProjectConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/TSProjectConsumer.java index 7bbcc4c906..90b57017dc 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/TSProjectConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/TSProjectConsumer.java @@ -1,9 +1,9 @@ package com.rusefi.output; +import com.devexperts.logging.Logging; import com.rusefi.*; import com.rusefi.util.LazyFileImpl; import com.rusefi.util.Output; -import com.rusefi.util.SystemOut; import org.jetbrains.annotations.NotNull; import java.io.*; @@ -14,6 +14,8 @@ import static com.rusefi.util.IoUtils.CHARSET; * [Constants] */ public class TSProjectConsumer implements ConfigurationConsumer { + private final static Logging log = Logging.getLogging(TSProjectConsumer.class); + private static final String TS_FILE_INPUT_NAME = "tunerstudio.template.ini"; private static final String CONFIG_DEFINITION_START = "CONFIG_DEFINITION_START"; private static final String CONFIG_DEFINITION_END = "CONFIG_DEFINITION_END"; @@ -41,7 +43,7 @@ public class TSProjectConsumer implements ConfigurationConsumer { protected void writeTunerStudioFile(String tsPath, String fieldsSection) throws IOException { TsFileContent tsContent = readTsTemplateInputFile(tsPath); - SystemOut.println("Got " + tsContent.getPrefix().length() + "/" + tsContent.getPostfix().length() + " of " + TS_FILE_INPUT_NAME); + log.info("Got " + tsContent.getPrefix().length() + "/" + tsContent.getPostfix().length() + " of " + TS_FILE_INPUT_NAME); // File.getPath() would eliminate potential separator at the end of the path String fileName = getTsFileOutputName(new File(ConfigDefinitionRootOutputFolder.getValue() + tsPath).getPath()); diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/pinout/PinoutLogic.java b/java_tools/configuration_definition/src/main/java/com/rusefi/pinout/PinoutLogic.java index 7cace05e99..d3f8380c52 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/pinout/PinoutLogic.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/pinout/PinoutLogic.java @@ -5,7 +5,6 @@ import com.rusefi.*; import com.rusefi.enum_reader.Value; import com.rusefi.newparse.DefinitionsState; import com.rusefi.newparse.parsing.Definition; -import com.rusefi.util.SystemOut; import org.jetbrains.annotations.NotNull; import org.yaml.snakeyaml.Yaml; @@ -140,14 +139,14 @@ public class PinoutLogic { Yaml yaml = new Yaml(); Map yamlData = yaml.load(reader); if (yamlData == null) { - SystemOut.println("Null yaml for " + yamlFile); + log.info("Null yaml for " + yamlFile); return; } Map metaMapping = processMetaHeader(yamlData); List> data = (List>) yamlData.get("pins"); if (data == null) { - SystemOut.println("Null yaml for " + yamlFile); + log.info("Null yaml for " + yamlFile); return; } log.info("Got from " + yamlFile + ": " + data); diff --git a/java_tools/configuration_definition_base/src/main/java/com/rusefi/ReaderStateImpl.java b/java_tools/configuration_definition_base/src/main/java/com/rusefi/ReaderStateImpl.java index d3a708d717..91471eaf8c 100644 --- a/java_tools/configuration_definition_base/src/main/java/com/rusefi/ReaderStateImpl.java +++ b/java_tools/configuration_definition_base/src/main/java/com/rusefi/ReaderStateImpl.java @@ -9,7 +9,6 @@ import com.rusefi.output.*; import com.rusefi.parse.TokenUtil; import com.rusefi.parse.TypesHelper; import com.rusefi.util.LazyFile; -import com.rusefi.util.SystemOut; import org.jetbrains.annotations.NotNull; import java.io.*; @@ -117,7 +116,7 @@ public class ReaderStateImpl implements ReaderState { * this is the most important invocation - here we read the primary input file and generated code into all * the destinations/writers */ - SystemOut.println("Reading definition from " + Objects.requireNonNull(definitionInputFile)); + log.info("Reading definition from " + Objects.requireNonNull(definitionInputFile)); String fileNameWithRoot = RootHolder.ROOT + definitionInputFile; try (BufferedReader definitionReader = new BufferedReader(readerProvider.read(fileNameWithRoot))) { readBufferedReader(definitionReader, destinations); diff --git a/java_tools/configuration_definition_base/src/main/java/com/rusefi/output/CHeaderConsumer.java b/java_tools/configuration_definition_base/src/main/java/com/rusefi/output/CHeaderConsumer.java index 7f0ebd6a79..dd9978f072 100644 --- a/java_tools/configuration_definition_base/src/main/java/com/rusefi/output/CHeaderConsumer.java +++ b/java_tools/configuration_definition_base/src/main/java/com/rusefi/output/CHeaderConsumer.java @@ -1,12 +1,13 @@ package com.rusefi.output; +import com.devexperts.logging.Logging; import com.rusefi.*; import com.rusefi.util.LazyFile; import com.rusefi.util.LazyFileImpl; -import com.rusefi.util.SystemOut; import java.io.IOException; +import static com.devexperts.logging.Logging.getLogging; import static com.rusefi.ToolUtil.EOL; import org.jetbrains.annotations.NotNull; @@ -15,6 +16,7 @@ import org.jetbrains.annotations.NotNull; * Configuration consumer which writes C header file */ public class CHeaderConsumer extends BaseCHeaderConsumer { + private static final Logging log = getLogging(CHeaderConsumer.class); @NotNull private final ReaderState state; /** @@ -29,13 +31,13 @@ public class CHeaderConsumer extends BaseCHeaderConsumer { this.variableRegistry = state.getVariableRegistry(); this.state = state; this.withC_Defines = withC_Defines; - SystemOut.println("Writing C header to " + destCHeader); + log.info("Writing C header to " + destCHeader); cHeader = fileFactory.create(destCHeader); } public static void writeDefinesToFile(VariableRegistry variableRegistry, String fileName, String headerComment) throws IOException { - SystemOut.println("Writing to " + fileName); + log.info("Writing to " + fileName); LazyFile cHeader = new LazyFileImpl(fileName); cHeader.write("//\n// " + ToolUtil.getGeneratedAutomaticallyTag() + headerComment + "\n//\n\n"); diff --git a/java_tools/configuration_definition_base/src/main/java/com/rusefi/parse/TypesHelper.java b/java_tools/configuration_definition_base/src/main/java/com/rusefi/parse/TypesHelper.java index 81658e645e..58e639203f 100644 --- a/java_tools/configuration_definition_base/src/main/java/com/rusefi/parse/TypesHelper.java +++ b/java_tools/configuration_definition_base/src/main/java/com/rusefi/parse/TypesHelper.java @@ -1,15 +1,18 @@ package com.rusefi.parse; +import com.devexperts.logging.Logging; import com.rusefi.ReaderState; -import com.rusefi.util.SystemOut; import java.util.Objects; +import static com.devexperts.logging.Logging.getLogging; + /** * TODO: migrate to Type? * 1/22/15 */ public class TypesHelper { + private static final Logging log = getLogging(TypesHelper.class); private static final String INT8_T = "int8_t"; public static final String UINT8_T = "uint8_t"; public static final String UINT_16_T = "uint16_t"; @@ -80,7 +83,7 @@ public class TypesHelper { return "S08"; if (UINT8_T.equals(type)) return "U08"; - SystemOut.println("No TS type conversion for " + type); + log.info("No TS type conversion for " + type); return type; } diff --git a/java_tools/enum_to_string/src/main/java/com/rusefi/EnumToString.java b/java_tools/enum_to_string/src/main/java/com/rusefi/EnumToString.java index ed77afd9cb..2509ac1161 100644 --- a/java_tools/enum_to_string/src/main/java/com/rusefi/EnumToString.java +++ b/java_tools/enum_to_string/src/main/java/com/rusefi/EnumToString.java @@ -1,9 +1,9 @@ package com.rusefi; +import com.devexperts.logging.Logging; import com.rusefi.enum_reader.Value; import com.rusefi.util.LazyFile; import com.rusefi.util.LazyFileImpl; -import com.rusefi.util.SystemOut; import java.io.*; import java.util.*; @@ -15,6 +15,7 @@ import java.util.*; */ @SuppressWarnings("StringConcatenationInsideStringBufferAppend") public class EnumToString { + private final static Logging log = Logging.getLogging(EnumToString.class); private final StringBuilder cppFileContent = new StringBuilder(); private final StringBuilder includesSection = new StringBuilder(); @@ -56,7 +57,7 @@ public class EnumToString { state.cppFileContent.insert(0, state.includesSection); headerFileContent.insert(0, state.includesSection); - SystemOut.println("includesSection:\n" + state.includesSection + "end of includesSection\n"); + log.info("includesSection:\n" + state.includesSection + "end of includesSection\n"); state.cppFileContent.insert(0, "#include \"global.h\"\n"); headerFileContent.insert(0, commonFilesHeader); @@ -64,7 +65,6 @@ public class EnumToString { new File(outputPath).mkdirs(); state.writeCppAndHeaderFiles(outputPath + File.separator + "auto_generated_" + InvokeReader.fileSuffix); - SystemOut.close(); } private void writeCppAndHeaderFiles(String outFileName) throws IOException { @@ -80,7 +80,7 @@ public class EnumToString { public void consumeFile(EnumsReader enumsReader, String inputPath, String headerInputFileName) throws IOException { Objects.requireNonNull(inputPath, "inputPath"); File f = new File(inputPath + File.separator + headerInputFileName); - SystemOut.println("Reading enums from " + headerInputFileName); + log.info("Reading enums from " + headerInputFileName); commonFilesHeader.insert(0, "// " + LazyFile.LAZY_FILE_TAG + " from " + f.getName() + " "); @@ -89,7 +89,7 @@ public class EnumToString { } public void outputData(EnumsReader enumsReader) { - SystemOut.println("Preparing output for " + enumsReader.getEnums().size() + " enums\n"); + log.info("Preparing output for " + enumsReader.getEnums().size() + " enums\n"); for (Map.Entry e : enumsReader.getEnums().entrySet()) { String enumName = e.getKey(); @@ -101,7 +101,7 @@ public class EnumToString { if (enumState.isEnumClass) headerFileContent.append("#endif //__cplusplus\n"); } - SystemOut.println("EnumToString: " + headerFileContent.length() + " bytes of content\n"); + log.info("EnumToString: " + headerFileContent.length() + " bytes of content\n"); } private static String makeCode(String enumName, EnumsReader.EnumState enumState) { diff --git a/java_tools/enum_to_string/src/main/java/com/rusefi/InvokeReader.java b/java_tools/enum_to_string/src/main/java/com/rusefi/InvokeReader.java index 37399d2914..78c0eb901e 100644 --- a/java_tools/enum_to_string/src/main/java/com/rusefi/InvokeReader.java +++ b/java_tools/enum_to_string/src/main/java/com/rusefi/InvokeReader.java @@ -1,13 +1,13 @@ package com.rusefi; -import com.rusefi.util.SystemOut; +import com.devexperts.logging.Logging; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Objects; public class InvokeReader { + private final static Logging log = Logging.getLogging(InvokeReader.class); private final static String KEY_INPUT_PATH = "-enumInputPath"; private final static String KEY_OUTPUT = "-outputPath"; private final static String KEY_OUTPUT_FILE = "-generatedFile"; @@ -22,7 +22,7 @@ public class InvokeReader { public InvokeReader(String... args) { if (args.length < 4) { - SystemOut.println("Please specify at least\n\n" + + log.error("Please specify at least\n\n" + EnumToString.KEY_ENUM_INPUT_FILE + "XXX\n" + KEY_OUTPUT + "XXX\n" ); diff --git a/java_tools/enum_to_string/src/main/java/com/rusefi/ToJavaEnum.java b/java_tools/enum_to_string/src/main/java/com/rusefi/ToJavaEnum.java index faf936408c..5cfffef01c 100644 --- a/java_tools/enum_to_string/src/main/java/com/rusefi/ToJavaEnum.java +++ b/java_tools/enum_to_string/src/main/java/com/rusefi/ToJavaEnum.java @@ -1,7 +1,7 @@ package com.rusefi; +import com.devexperts.logging.Logging; import com.rusefi.enum_reader.Value; -import com.rusefi.util.SystemOut; import java.io.BufferedWriter; import java.io.File; @@ -15,6 +15,7 @@ import java.util.Map; * produces java enum class from an enum defined in a C/C++ header */ public class ToJavaEnum { + private final static Logging log = Logging.getLogging(ToJavaEnum.class); static private boolean enumWithValues = false; public static void main(String[] args) throws IOException { @@ -34,7 +35,7 @@ public class ToJavaEnum { for (String inputFile : invokeReader.getInputFiles()) { File f = new File(invokeReader.getInputPath() + File.separator + inputFile); - SystemOut.println("Reading enums from " + f); + log.info("Reading enums from " + f); sb.append("// based on ").append(f).append("\n"); enumsReader.read(new FileReader(f), registry, enumWithValues);