logging refactoring

This commit is contained in:
rusefi 2020-07-02 20:10:22 -04:00
parent 8ac4864bba
commit 83833df6d9
20 changed files with 61 additions and 23 deletions

View File

@ -9,6 +9,7 @@
<module fileurl="file://$PROJECT_DIR$/inifile/inifile.iml" filepath="$PROJECT_DIR$/inifile/inifile.iml" />
<module fileurl="file://$PROJECT_DIR$/io/io.iml" filepath="$PROJECT_DIR$/io/io.iml" />
<module fileurl="file://$PROJECT_DIR$/logging/logging.iml" filepath="$PROJECT_DIR$/logging/logging.iml" />
<module fileurl="file://$PROJECT_DIR$/logging-api/logging-api.iml" filepath="$PROJECT_DIR$/logging-api/logging-api.iml" />
<module fileurl="file://$PROJECT_DIR$/models/models.iml" filepath="$PROJECT_DIR$/models/models.iml" />
<module fileurl="file://$PROJECT_DIR$/opensr5/opensr5.iml" filepath="$PROJECT_DIR$/opensr5/opensr5.iml" />
<module fileurl="file://$PROJECT_DIR$/romraider/romraider.iml" filepath="$PROJECT_DIR$/romraider/romraider.iml" />

View File

@ -555,7 +555,7 @@ public class AutoTest {
boolean failed = false;
try {
LinkManager linkManager = new LinkManager();
LinkManager linkManager = new LinkManager(FileLog.LOGGER);
IoUtil.connectToSimulator(linkManager, startSimulator);
new AutoTest(linkManager, linkManager.getCommandQueue()).mainTestBody();
} catch (Throwable e) {

View File

@ -12,7 +12,7 @@ public class EnduranceTest {
private static final int DEFAULT_COUNT = 2000;
public static void main(String[] args) {
LinkManager linkManager = new LinkManager();
LinkManager linkManager = new LinkManager(FileLog.LOGGER);
CommandQueue commandQueue = linkManager.getCommandQueue();
long start = System.currentTimeMillis();
int count = parseCount(args);

View File

@ -83,7 +83,7 @@ public class RealHwTest {
}
private static void runRealHardwareTest(String port) throws Exception {
LinkManager linkManager = new LinkManager();
LinkManager linkManager = new LinkManager(FileLog.LOGGER);
IoUtil.realHardwareConnect(linkManager, port);
new AutoTest(linkManager, linkManager.getCommandQueue()).mainTestBody();
}

View File

@ -49,6 +49,7 @@
<src path="inifile/src"/>
<src path="shared_ui/src"/>
<src path="shared_io/src/main/java"/>
<src path="logging-api/src/main/java"/>
<src path="ui/src/main/java"/>
<src path="ui/src/test/java"/>
<src path="romraider/src"/>

View File

@ -12,5 +12,6 @@
<orderEntry type="library" exported="" name="jcip-annotations" level="project" />
<orderEntry type="library" name="jSerialComm" level="project" />
<orderEntry type="module" module-name="opensr5" exported="" />
<orderEntry type="module" module-name="logging-api" exported="" />
</component>
</module>

View File

@ -57,9 +57,6 @@ public class BinaryProtocol implements BinaryProtocolCommands {
* todo: finish this feature, assuming we even need it.
*/
public static boolean PLAIN_PROTOCOL = Boolean.getBoolean(USE_PLAIN_PROTOCOL_PROPERTY);
static {
FileLog.MAIN.logLine(USE_PLAIN_PROTOCOL_PROPERTY + ": " + PLAIN_PROTOCOL);
}
private final LinkManager linkManager;
private final Logger logger;
@ -103,15 +100,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
state.setCurrentOutputs(currentOutputs);
}
private SensorCentral.SensorListener rpmListener = value -> {
if (value <= COMPOSITE_OFF_RPM) {
needCompositeLogger = true;
lastLowRpmTime = System.currentTimeMillis();
} else if (System.currentTimeMillis() - lastLowRpmTime > HIGH_RPM_DELAY * Timeouts.SECOND) {
FileLog.MAIN.logLine("Time to turn off composite logging");
needCompositeLogger = false;
}
};
private SensorCentral.SensorListener rpmListener;
private final Thread hook = new Thread(() -> closeComposites());
@ -122,6 +111,15 @@ public class BinaryProtocol implements BinaryProtocolCommands {
incomingData = createDataBuffer(stream, logger);
Runtime.getRuntime().addShutdownHook(hook);
rpmListener = value -> {
if (value <= COMPOSITE_OFF_RPM) {
needCompositeLogger = true;
lastLowRpmTime = System.currentTimeMillis();
} else if (System.currentTimeMillis() - lastLowRpmTime > HIGH_RPM_DELAY * Timeouts.SECOND) {
logger.info("Time to turn off composite logging");
needCompositeLogger = false;
}
};
}
public static IncomingDataBuffer createDataBuffer(IoStream stream, Logger logger) {
@ -149,7 +147,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
}
public void doSend(final String command, boolean fireEvent) throws InterruptedException {
FileLog.MAIN.logLine("Sending [" + command + "]");
logger.info("Sending [" + command + "]");
if (fireEvent && LinkManager.LOG_LEVEL.isDebugEnabled()) {
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(BinaryProtocol.class, "Sending [" + command + "]");
}
@ -221,7 +219,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
}
sleep(Timeouts.TEXT_PULL_PERIOD);
}
FileLog.MAIN.logLine("Stopping text pull");
logger.info("Stopping text pull");
}
};
Thread tr = new Thread(textPull);

View File

@ -1,6 +1,7 @@
package com.rusefi.io;
import com.fazecast.jSerialComm.SerialPort;
import com.opensr5.Logger;
import com.rusefi.FileLog;
import com.rusefi.NamedThreadFactory;
import com.rusefi.binaryprotocol.BinaryProtocol;
@ -31,9 +32,14 @@ public class LinkManager {
public static final String LOG_VIEWER = "log viewer";
private final CommandQueue commandQueue = new CommandQueue(this);
private final Logger logger;
private LinkConnector connector;
public LinkManager(Logger logger) {
this.logger = logger;
}
@NotNull
public CountDownLatch connect(String port) {
final CountDownLatch connected = new CountDownLatch(1);

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -22,6 +22,11 @@ public interface Logger {
public void error(String msg) {
System.err.println(new Date() + " " + msg);
}
@Override
public boolean isTradeEnabled() {
return false;
}
};
void trace(String msg);
@ -29,4 +34,6 @@ public interface Logger {
void info(String msg);
void error(String msg);
boolean isTradeEnabled();
}

View File

@ -8,5 +8,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="annotations" level="project" />
<orderEntry type="module" module-name="logging-api" />
</component>
</module>

View File

@ -30,6 +30,11 @@ public enum FileLog {
public void trace(String msg) {
}
@Override
public boolean isTradeEnabled() {
return false;
}
@Override
public void info(String msg) {
MAIN.logLine(msg);

View File

@ -2,6 +2,7 @@ package com.rusefi.io.test;
import com.opensr5.ConfigurationImage;
import com.opensr5.ini.field.ScalarIniField;
import com.rusefi.FileLog;
import com.rusefi.binaryprotocol.BinaryProtocolState;
import com.rusefi.config.Field;
import com.rusefi.config.generated.Fields;
@ -30,7 +31,7 @@ public class TcpCommunicationIntegrationTest {
state.setController(ci);
state.setCurrentOutputs(new byte[1 + Fields.TS_OUTPUT_SIZE]);
LinkManager linkManager = new LinkManager();
LinkManager linkManager = new LinkManager(FileLog.LOGGER);
linkManager.setConnector(LinkConnector.getDetachedConnector(state));
BinaryProtocolServer server = new BinaryProtocolServer();
server.start(linkManager, port);
@ -39,7 +40,7 @@ public class TcpCommunicationIntegrationTest {
// todo: remove CONFIGURATION_RUSEFI_BINARY or nicer API to disable local file load
LinkManager clientManager = new LinkManager();
LinkManager clientManager = new LinkManager(FileLog.LOGGER);
clientManager.startAndConnect(Integer.toString(port), new ConnectionStateListener() {
@Override
public void onConnectionEstablished() {

View File

@ -1,5 +1,6 @@
package com.rusefi.autodetect;
import com.rusefi.FileLog;
import com.rusefi.IoUtil;
import com.rusefi.io.ConnectionStatusLogic;
import com.rusefi.io.LinkManager;
@ -10,7 +11,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class ReconnectSandbox {
public static void main(String[] args) {
LinkManager linkManager = new LinkManager();
LinkManager linkManager = new LinkManager(FileLog.LOGGER);
LightweightGUI.waitForDeviceAndStart(linkManager);

View File

@ -195,7 +195,7 @@ public class ConsoleTools {
System.err.println("rusEFI not detected");
return;
}
LinkManager linkManager = new LinkManager();
LinkManager linkManager = new LinkManager(FileLog.LOGGER);
linkManager.startAndConnect(autoDetectedPort, new ConnectionStateListener() {
@Override
public void onConnectionEstablished() {

View File

@ -1,12 +1,13 @@
package com.rusefi.ui;
import com.rusefi.FileLog;
import com.rusefi.SensorSnifferCentral;
import com.rusefi.io.CommandQueue;
import com.rusefi.io.LinkManager;
import com.rusefi.sensor_logs.SensorLogger;
public class UIContext {
private final LinkManager linkManager = new LinkManager();
private final LinkManager linkManager = new LinkManager(FileLog.LOGGER);
public SensorLogger sensorLogger = new SensorLogger(this);
public GaugesPanel.DetachedRepository DetachedRepositoryINSTANCE = new GaugesPanel.DetachedRepository(this);

View File

@ -1,6 +1,7 @@
package com.rusefi.io.tcp.test;
import com.opensr5.ConfigurationImage;
import com.rusefi.FileLog;
import com.rusefi.binaryprotocol.BinaryProtocolState;
import com.rusefi.config.generated.Fields;
import com.rusefi.io.LinkConnector;
@ -13,7 +14,7 @@ class BinaryProtocolServerSandbox {
state.setController(new ConfigurationImage(new byte[Fields.TOTAL_CONFIG_SIZE]));
state.setCurrentOutputs(new byte[1 + Fields.TS_OUTPUT_SIZE]);
LinkManager linkManager = new LinkManager();
LinkManager linkManager = new LinkManager(FileLog.LOGGER);
linkManager.setConnector(LinkConnector.getDetachedConnector(state));
new BinaryProtocolServer().start(linkManager);
}

View File

@ -7,6 +7,7 @@
<module fileurl="file://$PROJECT_DIR$/../enum_to_string/enum_to_string.iml" filepath="$PROJECT_DIR$/../enum_to_string/enum_to_string.iml" />
<module fileurl="file://$PROJECT_DIR$/../../java_console/inifile/inifile.iml" filepath="$PROJECT_DIR$/../../java_console/inifile/inifile.iml" />
<module fileurl="file://$PROJECT_DIR$/../../java_console/logging/logging.iml" filepath="$PROJECT_DIR$/../../java_console/logging/logging.iml" />
<module fileurl="file://$PROJECT_DIR$/../../java_console/logging-api/logging-api.iml" filepath="$PROJECT_DIR$/../../java_console/logging-api/logging-api.iml" />
<module fileurl="file://$PROJECT_DIR$/../../java_console/models/models.iml" filepath="$PROJECT_DIR$/../../java_console/models/models.iml" />
<module fileurl="file://$PROJECT_DIR$/../../java_console/shared_io/shared_io.iml" filepath="$PROJECT_DIR$/../../java_console/shared_io/shared_io.iml" />
</modules>

View File

@ -20,6 +20,7 @@
<src path="${console_path}/autoupdate/src"/>
<src path="${console_path}/inifile/src"/>
<src path="${console_path}/logging/src"/>
<src path="${console_path}/logging-api/src/main/java"/>
<src path="${console_path}/models/src"/>
<src path="${console_path}/shared_io/src/main/java"/>
<src path="../enum_to_string/src"/>

View File

@ -20,6 +20,7 @@
<src path="${console_path}/shared_io/src/main/java"/>
<src path="${console_path}/inifile/src"/>
<src path="${console_path}/logging/src"/>
<src path="${console_path}/logging-api/src/main/java"/>
<src path="${console_path}/models/src"/>
<src path="${launcher_path}/src"/>
<src path="src"/>