logging refactoring

This commit is contained in:
rusefi 2020-07-02 20:39:10 -04:00
parent 83833df6d9
commit 7224a8cb31
38 changed files with 162 additions and 141 deletions

View File

@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="AverageAnglesUtil" type="Application" factoryName="Application" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.rusefi.AverageAnglesUtil" />
<module name="io" />
<module name="autotest" />
<option name="PROGRAM_PARAMETERS" value="a.csv" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<extension name="coverage">

View File

@ -9,5 +9,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="io" />
<orderEntry type="module" module-name="models" />
<orderEntry type="module" module-name="logging" />
</component>
</module>

View File

@ -8,7 +8,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="models" exported="" />
<orderEntry type="module" module-name="logging" exported="" />
<orderEntry type="library" exported="" name="jcip-annotations" level="project" />
<orderEntry type="library" name="jSerialComm" level="project" />
<orderEntry type="module" module-name="opensr5" exported="" />

View File

@ -5,7 +5,6 @@ import com.opensr5.Logger;
import com.opensr5.io.ConfigurationImageFile;
import com.opensr5.io.DataListener;
import com.rusefi.ConfigurationImageDiff;
import com.rusefi.FileLog;
import com.rusefi.Timeouts;
import com.rusefi.composite.CompositeEvent;
import com.rusefi.composite.CompositeParser;
@ -143,7 +142,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
@NotNull
public static String getFileName(String prefix, String fileType) {
return FileLog.DIR + prefix + FileLog.getDate() + fileType;
return Logger.DIR + prefix + Logger.getDate() + fileType;
}
public void doSend(final String command, boolean fireEvent) throws InterruptedException {
@ -520,7 +519,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
Thread.sleep(100);
return new String(response, 1, response.length - 1);
} catch (InterruptedException e) {
FileLog.MAIN.log(e);
logger.error(e.toString());
return null;
}
}

View File

@ -1,6 +1,6 @@
package com.rusefi.io;
import com.rusefi.FileLog;
import com.opensr5.Logger;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.MessagesCentral;
import org.jetbrains.annotations.NotNull;
@ -35,21 +35,7 @@ public class CommandQueue {
private final BlockingQueue<IMethodInvocation> pendingCommands = new LinkedBlockingQueue<>();
private final List<CommandQueueListener> commandListeners = new ArrayList<>();
private final Runnable runnable = new Runnable() {
@SuppressWarnings("InfiniteLoopStatement")
@Override
public void run() {
MessagesCentral.getInstance().postMessage(COMMAND_QUEUE_CLASS, "SerialIO started");
while (true) {
try {
sendPendingCommand();
} catch (Throwable e) {
FileLog.MAIN.logException("CommandQueue error", e);
System.exit(-2);
}
}
}
};
private final Runnable runnable;
private static boolean isSlowCommand(String cmd) {
String lc = cmd.toLowerCase();
@ -114,8 +100,23 @@ public class CommandQueue {
MessagesCentral.getInstance().postMessage(CommandQueue.class, "Took " + counter + " attempts");
}
public CommandQueue(LinkManager linkManager) {
public CommandQueue(LinkManager linkManager, Logger logger) {
this.linkManager = linkManager;
runnable = new Runnable() {
@SuppressWarnings("InfiniteLoopStatement")
@Override
public void run() {
MessagesCentral.getInstance().postMessage(COMMAND_QUEUE_CLASS, "SerialIO started");
while (true) {
try {
sendPendingCommand();
} catch (Throwable e) {
logger.error("CommandQueue error" + e);
System.exit(-2);
}
}
}
};
Thread thread = new Thread(runnable, "Commands Queue");
thread.setDaemon(true);
thread.start();

View File

@ -2,7 +2,6 @@ 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;
import com.rusefi.binaryprotocol.BinaryProtocolState;
@ -31,13 +30,21 @@ public class LinkManager {
};
public static final String LOG_VIEWER = "log viewer";
private final CommandQueue commandQueue = new CommandQueue(this);
private final CommandQueue commandQueue;
private final Logger logger;
private LinkConnector connector;
public LinkManager(Logger logger) {
this.logger = logger;
engineState = new EngineState(new EngineState.EngineStateListenerImpl() {
@Override
public void beforeLine(String fullLine) {
logger.info(fullLine);
HeartBeatListeners.onDataArrived();
}
});
commandQueue = new CommandQueue(this, logger);
}
@NotNull
@ -151,13 +158,7 @@ public class LinkManager {
// throw new IllegalStateException("Communication on wrong thread");
}
private EngineState engineState = new EngineState(new EngineState.EngineStateListenerImpl() {
@Override
public void beforeLine(String fullLine) {
FileLog.MAIN.logLine(fullLine);
HeartBeatListeners.onDataArrived();
}
});
private EngineState engineState;
public EngineState getEngineState() {
return engineState;
@ -176,14 +177,14 @@ public class LinkManager {
public void start(String port) {
Objects.requireNonNull(port, "port");
FileLog.MAIN.logLine("LinkManager: Starting " + port);
logger.info("LinkManager: Starting " + port);
if (isLogViewerMode(port)) {
connector = LinkConnector.VOID;
} else if (TcpConnector.isTcpPort(port)) {
connector = new TcpConnector(this, port);
connector = new TcpConnector(this, port, logger);
isSimulationMode = true;
} else {
connector = new SerialConnector(this, port);
connector = new SerialConnector(this, port, logger);
}
}

View File

@ -1,6 +1,6 @@
package com.rusefi.io.serial;
import com.rusefi.FileLog;
import com.opensr5.Logger;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.io.CommunicationLoggingHolder;
import com.rusefi.io.ConnectionStateListener;
@ -20,6 +20,7 @@ import java.awt.*;
*/
public class PortHolder {
private final DataListener dataListener;
private final Logger logger;
private final LinkManager linkManager;
public ConnectionStateListener listener;
@ -28,9 +29,10 @@ public class PortHolder {
@Nullable
private BinaryProtocol bp;
protected PortHolder(LinkManager linkManager) {
protected PortHolder(LinkManager linkManager, Logger logger) {
this.linkManager = linkManager;
dataListener = freshData -> linkManager.getEngineState().processNewData(new String(freshData), LinkManager.ENCODER);
this.logger = logger;
}
public String port;
@ -41,9 +43,9 @@ public class PortHolder {
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(getClass(), "Opening port: " + port);
IoStream stream = SerialIoStreamJSerialComm.openPort(port);
IoStream stream = SerialIoStreamJSerialComm.openPort(port, logger);
synchronized (portLock) {
bp = new BinaryProtocol(linkManager, FileLog.LOGGER, stream);
bp = new BinaryProtocol(linkManager, logger, stream);
portLock.notifyAll();
}

View File

@ -1,6 +1,6 @@
package com.rusefi.io.serial;
import com.rusefi.FileLog;
import com.opensr5.Logger;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.core.MessagesCentral;
import com.rusefi.io.ConnectionStateListener;
@ -14,23 +14,25 @@ import com.rusefi.io.LinkManager;
public class SerialConnector implements LinkConnector {
private final PortHolder portHolder;
private final Logger logger;
private final LinkManager linkManager;
public SerialConnector(LinkManager linkManager, String serialPort) {
public SerialConnector(LinkManager linkManager, String serialPort, Logger logger) {
this.linkManager = linkManager;
portHolder = new PortHolder(linkManager);
portHolder = new PortHolder(linkManager, logger);
this.logger = logger;
portHolder.port = serialPort;
}
@Override
public void connectAndReadConfiguration(ConnectionStateListener listener) {
FileLog.MAIN.logLine("SerialConnector: connecting");
logger.info("SerialConnector: connecting");
portHolder.listener = listener;
FileLog.MAIN.logLine("scheduleOpening");
logger.info("scheduleOpening");
linkManager.execute(new Runnable() {
@Override
public void run() {
FileLog.MAIN.logLine("scheduleOpening>openPort");
logger.info("scheduleOpening>openPort");
portHolder.connectAndReadConfiguration();
}
});

View File

@ -3,8 +3,8 @@ package com.rusefi.io.serial;
import com.fazecast.jSerialComm.SerialPort;
import com.fazecast.jSerialComm.SerialPortDataListener;
import com.fazecast.jSerialComm.SerialPortEvent;
import com.opensr5.Logger;
import com.opensr5.io.DataListener;
import com.rusefi.FileLog;
import com.rusefi.io.IoStream;
/**
@ -17,13 +17,15 @@ public class SerialIoStreamJSerialComm implements IoStream {
private boolean isClosed;
private SerialPort sp;
private final String port;
private final Logger logger;
/**
* @see #openPort(String)
* @see #openPort(String, Logger)
*/
private SerialIoStreamJSerialComm(SerialPort sp, String port) {
private SerialIoStreamJSerialComm(SerialPort sp, String port, Logger logger) {
this.sp = sp;
this.port = port;
this.logger = logger;
}
@Override
@ -59,10 +61,10 @@ public class SerialIoStreamJSerialComm implements IoStream {
@Override
public void close() {
FileLog.LOGGER.info(port + ": Closing port...");
logger.info(port + ": Closing port...");
isClosed = true;
sp.closePort();
FileLog.LOGGER.info(port + ": Closed port.");
logger.info(port + ": Closed port.");
}
@Override
@ -79,12 +81,12 @@ public class SerialIoStreamJSerialComm implements IoStream {
* Just open physical serial and not much more
* @see PortHolder#connectAndReadConfiguration()
*/
public static IoStream openPort(String port) {
FileLog.LOGGER.info("[SerialIoStreamJSerialComm] openPort " + port);
public static IoStream openPort(String port, Logger logger) {
logger.info("[SerialIoStreamJSerialComm] openPort " + port);
SerialPort serialPort = SerialPort.getCommPort(port);
serialPort.setBaudRate(BaudRateHolder.INSTANCE.baudRate);
serialPort.openPort(0);
// FileLog.LOGGER.info("[SerialIoStreamJSerialComm] opened " + port);
return new SerialIoStreamJSerialComm(serialPort, port);
return new SerialIoStreamJSerialComm(serialPort, port, logger);
}
}

View File

@ -1,7 +1,7 @@
package com.rusefi.io.tcp;
import com.opensr5.ConfigurationImage;
import com.rusefi.FileLog;
import com.opensr5.Logger;
import com.rusefi.binaryprotocol.BinaryProtocolCommands;
import com.rusefi.binaryprotocol.BinaryProtocolState;
import com.rusefi.binaryprotocol.IoHelper;
@ -28,15 +28,20 @@ import static com.rusefi.config.generated.Fields.*;
public class BinaryProtocolServer implements BinaryProtocolCommands {
private static final int DEFAULT_PROXY_PORT = 2390;
private static final String TS_OK = "\0";
private final Logger logger;
public AtomicInteger unknownCommands = new AtomicInteger();
public BinaryProtocolServer(Logger logger) {
this.logger = logger;
}
public void start(LinkManager linkManager) {
start(linkManager, DEFAULT_PROXY_PORT);
}
public void start(LinkManager linkManager, int port) {
FileLog.MAIN.logLine("BinaryProtocolServer on " + port);
logger.info("BinaryProtocolServer on " + port);
Runnable runnable = new Runnable() {
@SuppressWarnings("InfiniteLoopStatement")
@Override
@ -45,7 +50,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
try {
serverSocket = new ServerSocket(port, 1);
} catch (IOException e) {
FileLog.MAIN.logException("Error binding server socket", e);
logger.error("Error binding server socket" + e);
return;
}
@ -53,14 +58,14 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
while (true) {
// Wait for a connection
final Socket clientSocket = serverSocket.accept();
FileLog.MAIN.logLine("Binary protocol proxy port connection");
logger.info("Binary protocol proxy port connection");
new Thread(new Runnable() {
@Override
public void run() {
try {
runProxy(linkManager, clientSocket);
} catch (IOException e) {
FileLog.MAIN.logLine("proxy connection: " + e);
logger.info("proxy connection: " + e);
}
}
}, "proxy connection").start();
@ -108,27 +113,27 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
if (crc != IoHelper.getCrc32(packet))
throw new IllegalStateException("CRC mismatch");
TcpIoStream stream = new TcpIoStream(linkManager, clientSocket);
TcpIoStream stream = new TcpIoStream(logger, linkManager, clientSocket);
if (command == COMMAND_HELLO) {
stream.sendPacket((TS_OK + Fields.TS_SIGNATURE).getBytes(), FileLog.LOGGER);
stream.sendPacket((TS_OK + Fields.TS_SIGNATURE).getBytes(), logger);
} else if (command == COMMAND_PROTOCOL) {
// System.out.println("Ignoring crc F command");
stream.sendPacket((TS_OK + TS_PROTOCOL).getBytes(), FileLog.LOGGER);
stream.sendPacket((TS_OK + TS_PROTOCOL).getBytes(), logger);
} else if (command == Fields.TS_GET_FIRMWARE_VERSION) {
stream.sendPacket((TS_OK + "rusEFI proxy").getBytes(), FileLog.LOGGER);
stream.sendPacket((TS_OK + "rusEFI proxy").getBytes(), logger);
} else if (command == COMMAND_CRC_CHECK_COMMAND) {
handleCrc(linkManager, stream);
} else if (command == COMMAND_PAGE) {
stream.sendPacket(TS_OK.getBytes(), FileLog.LOGGER);
stream.sendPacket(TS_OK.getBytes(), logger);
} else if (command == COMMAND_READ) {
handleRead(linkManager, dis, stream);
} else if (command == Fields.TS_CHUNK_WRITE_COMMAND) {
handleWrite(linkManager, packet, dis, stream);
} else if (command == Fields.TS_BURN_COMMAND) {
stream.sendPacket(new byte[]{TS_RESPONSE_BURN_OK}, FileLog.LOGGER);
stream.sendPacket(new byte[]{TS_RESPONSE_BURN_OK}, logger);
} else if (command == Fields.TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY) {
// todo: relay command
stream.sendPacket(TS_OK.getBytes(), FileLog.LOGGER);
stream.sendPacket(TS_OK.getBytes(), logger);
} else if (command == Fields.TS_OUTPUT_COMMAND) {
int offset = swap16(dis.readShort());
int count = swap16(dis.readShort());
@ -140,31 +145,31 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
byte[] currentOutputs = binaryProtocolState.getCurrentOutputs();
if (currentOutputs != null)
System.arraycopy(currentOutputs, 1 + offset , response, 1, count);
stream.sendPacket(response, FileLog.LOGGER);
stream.sendPacket(response, logger);
} else {
unknownCommands.incrementAndGet();
new IllegalStateException().printStackTrace();
FileLog.MAIN.logLine("Error: unknown command " + (char) command + "/" + command);
logger.info("Error: unknown command " + (char) command + "/" + command);
}
}
}
private static void handleWrite(LinkManager linkManager, byte[] packet, DataInputStream dis, TcpIoStream stream) throws IOException {
private void handleWrite(LinkManager linkManager, byte[] packet, DataInputStream dis, TcpIoStream stream) throws IOException {
dis.readShort(); // page
int offset = swap16(dis.readShort());
int count = swap16(dis.readShort());
FileLog.MAIN.logLine("TS_CHUNK_WRITE_COMMAND: offset=" + offset + " count=" + count);
logger.info("TS_CHUNK_WRITE_COMMAND: offset=" + offset + " count=" + count);
BinaryProtocolState bp = linkManager.getBinaryProtocolState();
bp.setRange(packet, 7, offset, count);
stream.sendPacket(TS_OK.getBytes(), FileLog.LOGGER);
stream.sendPacket(TS_OK.getBytes(), logger);
}
private static void handleRead(LinkManager linkManager, DataInputStream dis, TcpIoStream stream) throws IOException {
private void handleRead(LinkManager linkManager, DataInputStream dis, TcpIoStream stream) throws IOException {
short page = dis.readShort();
int offset = swap16(dis.readShort());
int count = swap16(dis.readShort());
if (count <= 0) {
FileLog.MAIN.logLine("Error: negative read request " + offset + "/" + count);
logger.info("Error: negative read request " + offset + "/" + count);
} else {
System.out.println("read " + page + "/" + offset + "/" + count);
BinaryProtocolState bp = linkManager.getBinaryProtocolState();
@ -174,11 +179,11 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
ConfigurationImage configurationImage = bp.getControllerConfiguration();
Objects.requireNonNull(configurationImage, "configurationImage");
System.arraycopy(configurationImage.getContent(), offset, response, 1, count);
stream.sendPacket(response, FileLog.LOGGER);
stream.sendPacket(response, logger);
}
}
private static void handleCrc(LinkManager linkManager, TcpIoStream stream) throws IOException {
private void handleCrc(LinkManager linkManager, TcpIoStream stream) throws IOException {
System.out.println("CRC check");
BinaryProtocolState bp = linkManager.getBinaryProtocolState();
byte[] content = bp.getControllerConfiguration().getContent();
@ -186,6 +191,6 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
ByteArrayOutputStream response = new ByteArrayOutputStream();
response.write(TS_OK.charAt(0));
new DataOutputStream(response).writeInt(result);
stream.sendPacket(response.toByteArray(), FileLog.LOGGER);
stream.sendPacket(response.toByteArray(), logger);
}
}

View File

@ -1,17 +1,14 @@
package com.rusefi.io.tcp;
import com.opensr5.Logger;
import com.opensr5.io.DataListener;
import com.rusefi.FileLog;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.core.ResponseBuffer;
import com.rusefi.io.ConnectionStateListener;
import com.rusefi.io.IoStream;
import com.rusefi.io.LinkConnector;
import com.rusefi.io.LinkManager;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Collection;
import java.util.Collections;
@ -26,11 +23,13 @@ public class TcpConnector implements LinkConnector {
private final int port;
private final String hostname;
private final LinkManager linkManager;
private final Logger logger;
private BinaryProtocol bp;
public TcpConnector(LinkManager linkManager, String port) {
public TcpConnector(LinkManager linkManager, String port, Logger logger) {
this.linkManager = linkManager;
this.logger = logger;
try {
this.port = getTcpPort(port);
this.hostname = getHostname(port);
@ -95,15 +94,15 @@ public class TcpConnector implements LinkConnector {
*/
@Override
public void connectAndReadConfiguration(ConnectionStateListener listener) {
FileLog.MAIN.logLine("Connecting to host=" + hostname + "/port=" + port);
logger.info("Connecting to host=" + hostname + "/port=" + port);
TcpIoStream tcpIoStream;
try {
Socket socket = new Socket(hostname, port);
tcpIoStream = new TcpIoStream(linkManager, socket);
tcpIoStream = new TcpIoStream(logger, linkManager, socket);
} catch (IOException e) {
listener.onConnectionFailed();
FileLog.MAIN.logLine("Failed to connect to " + hostname + "/port=" + port);
logger.error("Failed to connect to " + hostname + "/port=" + port);
return;
}
@ -122,7 +121,7 @@ public class TcpConnector implements LinkConnector {
};
// ioStream.setInputListener(listener1);
bp = new BinaryProtocol(linkManager, FileLog.LOGGER, tcpIoStream);
bp = new BinaryProtocol(linkManager, logger, tcpIoStream);
boolean result = bp.connectAndReadConfiguration(listener1);
if (result) {
@ -139,7 +138,7 @@ public class TcpConnector implements LinkConnector {
@Override
public void send(String command, boolean fireEvent) throws InterruptedException {
if (bp == null) {
FileLog.MAIN.logLine("Not connected");
logger.info("Not connected");
return;
}

View File

@ -1,6 +1,6 @@
package com.rusefi.io.tcp;
import com.rusefi.FileLog;
import com.opensr5.Logger;
import com.opensr5.io.DataListener;
import com.rusefi.io.IoStream;
import com.rusefi.io.LinkManager;
@ -19,14 +19,16 @@ import java.util.Arrays;
public class TcpIoStream implements IoStream {
private final InputStream input;
private final OutputStream output;
private final Logger logger;
private final LinkManager linkManager;
private boolean isClosed;
public TcpIoStream(LinkManager linkManager, Socket socket) throws IOException {
this(linkManager, new BufferedInputStream(socket.getInputStream()), socket.getOutputStream());
public TcpIoStream(Logger logger, LinkManager linkManager, Socket socket) throws IOException {
this(logger, linkManager, new BufferedInputStream(socket.getInputStream()), socket.getOutputStream());
}
public TcpIoStream(LinkManager linkManager, InputStream input, OutputStream output) {
private TcpIoStream(Logger logger, LinkManager linkManager, InputStream input, OutputStream output) {
this.logger = logger;
this.linkManager = linkManager;
if (input == null)
throw new NullPointerException("input");
@ -58,7 +60,7 @@ public class TcpIoStream implements IoStream {
@Override
public void run() {
Thread.currentThread().setName("TCP connector loop");
FileLog.MAIN.logLine("Running TCP connection loop");
logger.info("Running TCP connection loop");
byte inputBuffer[] = new byte[256];
while (true) {

View File

@ -1,5 +1,6 @@
package com.opensr5;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
@ -28,6 +29,12 @@ public interface Logger {
return false;
}
};
String DIR = "logs/";
String DATE_PATTERN = "yyyy-MM-dd_HH_mm_ss_SSS";
static String getDate() {
return new SimpleDateFormat(DATE_PATTERN).format(new Date());
}
void trace(String msg);

View File

@ -6,8 +6,6 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* what the hell is this anyway? todo: migrate to log4j2
@ -18,10 +16,8 @@ public enum FileLog {
MAIN,
SIMULATOR_CONSOLE;
public static final String DIR = "logs/";
public static final String LOG_INFO_TEXT = "Writing logs to '" + DIR + "'";
public static final String LOG_INFO_TEXT = "Writing logs to '" + Logger.DIR + "'";
public static final String OS_VERSION = "os.version";
public static final String DATE_PATTERN = "yyyy-MM-dd_HH_mm_ss_SSS";
private static final String WIKI_URL = "https://github.com/rusefi/rusefi/wiki/rusEFI-logs-folder";
public static String currentLogName;
public static final String END_OF_TIMESTAND_TAG = "<EOT>: ";
@ -67,7 +63,7 @@ public enum FileLog {
}
private static void writeReadmeFile() {
LazyFile file = new LazyFile(DIR + "README.html");
LazyFile file = new LazyFile(Logger.DIR + "README.html");
file.write("<center>" + "<a href='" + WIKI_URL + "'>More info online<br/><img src=https://raw.githubusercontent.com/wiki/rusefi/rusefi/logo.gif></a>");
try {
file.close();
@ -90,29 +86,25 @@ public enum FileLog {
}
private FileOutputStream openLog() throws FileNotFoundException {
String date = getDate();
String date = Logger.getDate();
createFolderIfNeeded();
currentLogName = name() + "_rfi_report_" + date + ".csv";
String fileName = DIR + currentLogName;
String fileName = Logger.DIR + currentLogName;
rlog("Writing to " + fileName);
return new FileOutputStream(fileName, true);
}
public static void createFolderIfNeeded() {
File dir = new File(DIR);
File dir = new File(Logger.DIR);
if (dir.exists())
return;
boolean created = dir.mkdirs();
if (!created)
throw new IllegalStateException("Failed to create " + DIR + " folder");
}
public static String getDate() {
return new SimpleDateFormat(DATE_PATTERN).format(new Date());
throw new IllegalStateException("Failed to create " + Logger.DIR + " folder");
}
public synchronized void logLine(String fullLine) {
String withDate = getDate() + END_OF_TIMESTAND_TAG + fullLine;
String withDate = Logger.getDate() + END_OF_TIMESTAND_TAG + fullLine;
System.out.println(withDate);
if (suspendLogging)
return;

View File

@ -9,5 +9,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="inifile" />
<orderEntry type="module" module-name="logging" />
<orderEntry type="module" module-name="logging-api" />
</component>
</module>

View File

@ -1,5 +1,6 @@
package com.rusefi.models;
import com.opensr5.Logger;
import com.rusefi.FileLog;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -26,7 +27,7 @@ public class XYData {
private double maxYValue;
private double minYValue;
String date = FileLog.getDate();
String date = Logger.getDate();
public XYData() {
clear();

View File

@ -33,7 +33,7 @@ public class TcpCommunicationIntegrationTest {
LinkManager linkManager = new LinkManager(FileLog.LOGGER);
linkManager.setConnector(LinkConnector.getDetachedConnector(state));
BinaryProtocolServer server = new BinaryProtocolServer();
BinaryProtocolServer server = new BinaryProtocolServer(FileLog.LOGGER);
server.start(linkManager, port);
CountDownLatch countDownLatch = new CountDownLatch(1);

View File

@ -1,5 +1,6 @@
package com.rusefi;
import com.opensr5.Logger;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.generated.Fields;
import com.rusefi.tracing.Entry;
@ -72,7 +73,7 @@ public class BenchTestPane {
List<Entry> data = Entry.parseBuffer(packet);
int rpm = RpmModel.getInstance().getValue();
String fileName = FileLog.getDate() + "_rpm_" + rpm + "_rusEfi_trace" + ".json";
String fileName = Logger.getDate() + "_rpm_" + rpm + "_rusEfi_trace" + ".json";
JsonOutput.writeToStream(data, new FileOutputStream(fileName));

View File

@ -1,6 +1,7 @@
package com.rusefi;
import com.fathzer.soft.javaluator.DoubleEvaluator;
import com.opensr5.Logger;
import java.io.*;
import java.util.List;
@ -32,7 +33,7 @@ public class CompileTool {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(outputFileName))) {
bw.write("// this https://en.wikipedia.org/wiki/Reverse_Polish_notation is generated automatically" + NEWLINE);
bw.write("// from " + inputFileName + NEWLINE);
bw.write("// on " + FileLog.getDate() + NEWLINE + "//" + NEWLINE);
bw.write("// on " + Logger.getDate() + NEWLINE + "//" + NEWLINE);
String line;
while ((line = br.readLine()) != null) {

View File

@ -1,10 +1,10 @@
package com.rusefi;
import com.opensr5.Logger;
import com.rusefi.core.MessagesCentral;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.file.TableGenerator;
import com.rusefi.io.CommandQueue;
import com.rusefi.models.Point3D;
import com.rusefi.models.Range;
import com.rusefi.models.XYData;
@ -80,7 +80,7 @@ public class EcuStimulator {
// if (1 == 1)
// return;
String csvFileName = "table_" + inputs.getRpmStep() + "_" + inputs.getEngineLoadStep() + FileLog.getDate() + ".csv";
String csvFileName = "table_" + inputs.getRpmStep() + "_" + inputs.getEngineLoadStep() + Logger.getDate() + ".csv";
FileLog.MAIN.logLine("Wring to " + csvFileName);
final BufferedWriter csv;
@ -121,7 +121,7 @@ public class EcuStimulator {
throw new IllegalStateException(e);
}
TableGenerator.writeAsC(data, C_PREFIX, "map" + FileLog.getDate() + ".c");
TableGenerator.writeAsC(data, C_PREFIX, "map" + Logger.getDate() + ".c");
}
private void buildTable(ResultListener listener, Sensor dwellSensor) {

View File

@ -1,5 +1,6 @@
package com.rusefi;
import com.opensr5.Logger;
import com.rusefi.config.generated.Fields;
import com.rusefi.ui.RpmLabel;
import com.rusefi.ui.RpmModel;
@ -77,7 +78,7 @@ public class SensorSnifferPane {
@Override
public void actionPerformed(ActionEvent e) {
int rpm = RpmModel.getInstance().getValue();
String fileName = FileLog.getDate() + "_rpm_" + rpm + "_sensor" + ".png";
String fileName = Logger.getDate() + "_rpm_" + rpm + "_sensor" + ".png";
UiUtils.saveImageWithPrompt(fileName, upperPanel, canvas);
}

View File

@ -6,6 +6,7 @@ import com.rusefi.io.LinkManager;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -33,7 +34,7 @@ public class PortDetector {
CountDownLatch portFound = new CountDownLatch(1);
AtomicReference<String> result = new AtomicReference<>();
for (String serialPort : serialPorts) {
Thread thread = new Thread(new SerialAutoChecker(serialPort, portFound, result, callback));
Thread thread = new Thread(new SerialAutoChecker(FileLog.LOGGER, serialPort, portFound, result, callback));
serialFinder.add(thread);
thread.start();
}

View File

@ -17,26 +17,28 @@ import java.util.function.Function;
import static com.rusefi.binaryprotocol.IoHelper.checkResponseCode;
public class SerialAutoChecker implements Runnable {
private final Logger logger;
private final String serialPort;
private final CountDownLatch portFound;
private final AtomicReference<String> result;
private final Function<IoStream, Void> callback;
public static String SIGNATURE;
public SerialAutoChecker(String serialPort, CountDownLatch portFound, AtomicReference<String> result, Function<IoStream, Void> callback) {
public SerialAutoChecker(Logger logger, String serialPort, CountDownLatch portFound, AtomicReference<String> result, Function<IoStream, Void> callback) {
this.logger = logger;
this.serialPort = serialPort;
this.portFound = portFound;
this.result = result;
this.callback = callback;
}
public SerialAutoChecker(String serialPort, CountDownLatch portFound, AtomicReference<String> result) {
this(serialPort, portFound, result, null);
public SerialAutoChecker(Logger logger, String serialPort, CountDownLatch portFound, AtomicReference<String> result) {
this(logger, serialPort, portFound, result, null);
}
@Override
public void run() {
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort);
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort, logger);
Logger logger = FileLog.LOGGER;
IncomingDataBuffer incomingData = BinaryProtocol.createDataBuffer(stream, logger);
try {

View File

@ -47,7 +47,7 @@ public class DfuFlasher {
if (!PortDetector.isAutoPort(port)) {
messages.append("Using selected " + port + "\n");
IoStream stream = SerialIoStreamJSerialComm.openPort(port);
IoStream stream = SerialIoStreamJSerialComm.openPort(port, FileLog.LOGGER);
sendDfuRebootCommand(stream, messages);
} else {
messages.append("Auto-detecting port...\n");

View File

@ -1,5 +1,6 @@
package com.rusefi.sensor_logs;
import com.opensr5.Logger;
import com.rusefi.FileLog;
import com.rusefi.config.FieldType;
import com.rusefi.config.generated.Fields;
@ -54,7 +55,7 @@ public class BinarySensorLog implements SensorLog {
public void writeSensorLogLine() {
if (stream == null) {
FileLog.createFolderIfNeeded();
fileName = FileLog.DIR + "rusEFI_gauges_" + FileLog.getDate() + ".mlg";
fileName = Logger.DIR + "rusEFI_gauges_" + Logger.getDate() + ".mlg";
try {
stream = new DataOutputStream(new FileOutputStream(fileName));

View File

@ -1,13 +1,13 @@
package com.rusefi.sensor_logs;
import com.opensr5.ConfigurationImage;
import com.opensr5.Logger;
import com.rusefi.FileLog;
import com.rusefi.Launcher;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.io.LinkManager;
import com.rusefi.ui.UIContext;
import com.rusefi.ui.config.ConfigField;
@ -41,14 +41,14 @@ public class PlainTextSensorLog implements SensorLog {
private void startSensorLogFile() {
FileLog.createFolderIfNeeded();
String fileName = FileLog.DIR + "rusEFI_gauges_" + FileLog.getDate() + ".msl";
String fileName = Logger.DIR + "rusEFI_gauges_" + Logger.getDate() + ".msl";
fileStartTime = System.currentTimeMillis();
try {
logFile = new FileWriter(fileName);
logFile.write("\"rusEFI console" + Launcher.CONSOLE_VERSION + " firmware " + Launcher.firmwareVersion.get() + "\"\r\n");
logFile.write("Captured " + FileLog.getDate() + "\r\n");
logFile.write("Captured " + Logger.getDate() + "\r\n");
int debugMode = -1;
BinaryProtocol bp = uiContext.getLinkManager().getCurrentStreamState();

View File

@ -134,7 +134,7 @@ public class ConsoleTools {
String autoDetectedPort = autoDetectPort();
if (autoDetectedPort == null)
return;
IoStream stream = SerialIoStreamJSerialComm.openPort(autoDetectedPort);
IoStream stream = SerialIoStreamJSerialComm.openPort(autoDetectedPort, FileLog.LOGGER);
byte[] commandBytes = BinaryProtocol.getTextCommandBytes(command);
stream.sendPacket(commandBytes, FileLog.LOGGER);
}
@ -199,7 +199,7 @@ public class ConsoleTools {
linkManager.startAndConnect(autoDetectedPort, new ConnectionStateListener() {
@Override
public void onConnectionEstablished() {
new BinaryProtocolServer().start(linkManager);
new BinaryProtocolServer(FileLog.LOGGER).start(linkManager);
}
@Override
@ -305,7 +305,7 @@ public class ConsoleTools {
System.out.println("rusEFI not detected");
return;
}
IoStream stream = SerialIoStreamJSerialComm.openPort(autoDetectedPort);
IoStream stream = SerialIoStreamJSerialComm.openPort(autoDetectedPort, FileLog.LOGGER);
Logger logger = FileLog.LOGGER;
IncomingDataBuffer incomingData = BinaryProtocol.createDataBuffer(stream, logger);
byte[] commandBytes = BinaryProtocol.getTextCommandBytes("hello");

View File

@ -1,6 +1,6 @@
package com.rusefi.ui;
import com.rusefi.FileLog;
import com.opensr5.Logger;
import com.rusefi.models.Range;
import com.rusefi.models.XYData;
import com.rusefi.ui.util.UiUtils;
@ -40,7 +40,7 @@ public class ChartHelper {
saveImageButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String fileName = FileLog.getDate() + "_3d.png";
String fileName = Logger.getDate() + "_3d.png";
UiUtils.saveImageWithPrompt(fileName, result, jsp);
}

View File

@ -1,6 +1,7 @@
package com.rusefi.ui;
import com.opensr5.ConfigurationImage;
import com.opensr5.Logger;
import com.rusefi.FileLog;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.generated.Fields;
@ -58,7 +59,7 @@ public class FormulasPane {
saveImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String fileName = FileLog.getDate() + "_formulas.png";
String fileName = Logger.getDate() + "_formulas.png";
UiUtils.saveImageWithPrompt(fileName, formulaProxy, formulaProxy);
}

View File

@ -1,5 +1,6 @@
package com.rusefi.ui;
import com.opensr5.Logger;
import com.romraider.Settings;
import com.romraider.maps.Scale;
import com.romraider.maps.Table;
@ -257,7 +258,7 @@ public class FuelTunePane {
private DataOutputStream getTuneLogStream() {
if (dos == null) {
String fileName = FileLog.DIR + "tune_" + FileLog.getDate() + ".txt";
String fileName = Logger.DIR + "tune_" + Logger.getDate() + ".txt";
try {
dos = new DataOutputStream(new FileOutputStream(fileName));
} catch (FileNotFoundException e) {

View File

@ -1,5 +1,6 @@
package com.rusefi.ui;
import com.opensr5.Logger;
import com.rusefi.FileLog;
import com.rusefi.PaneSettings;
import com.rusefi.core.Sensor;
@ -236,7 +237,7 @@ public class GaugesPanel {
saveImageButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String fileName = FileLog.getDate() + "_gauges.png";
String fileName = Logger.getDate() + "_gauges.png";
UiUtils.saveImageWithPrompt(fileName, content, gauges.panel);
}

View File

@ -1,6 +1,6 @@
package com.rusefi.ui;
import com.rusefi.FileLog;
import com.opensr5.Logger;
import com.rusefi.core.EngineState;
import com.rusefi.core.MessagesCentral;
import com.rusefi.io.CommandQueue;
@ -16,7 +16,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
public class MessagesView {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(FileLog.DATE_PATTERN);
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(Logger.DATE_PATTERN);
private static final int MAX_SIZE = 50000;
private final Style bold;

View File

@ -7,7 +7,6 @@ import com.rusefi.core.EngineState;
import com.rusefi.io.*;
import com.rusefi.io.tcp.BinaryProtocolServer;
import com.rusefi.maintenance.VersionChecker;
import com.rusefi.ui.GaugesPanel;
import com.rusefi.ui.storage.Node;
import com.rusefi.ui.util.FrameHelper;
import com.rusefi.ui.util.UiUtils;
@ -80,7 +79,7 @@ public class MainFrame {
tabbedPane.settingsTab.showContent();
tabbedPane.logsManager.showContent();
tabbedPane.fuelTunePane.showContent();
new BinaryProtocolServer().start(linkManager);
new BinaryProtocolServer(FileLog.LOGGER).start(linkManager);
}
});

View File

@ -1,11 +1,11 @@
package com.rusefi.ui.engine;
import com.opensr5.Logger;
import com.rusefi.FileLog;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.EngineState;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.io.LinkManager;
import com.rusefi.ui.*;
import com.rusefi.ui.config.BitConfigField;
import com.rusefi.ui.config.ConfigField;
@ -272,7 +272,7 @@ public class EngineSnifferPanel {
private void saveImage() {
int rpm = RpmModel.getInstance().getValue();
double maf = SensorCentral.getInstance().getValue(Sensor.MAF);
String fileName = FileLog.getDate() + "rpm_" + rpm + "_maf_" + maf + ".png";
String fileName = Logger.getDate() + "rpm_" + rpm + "_maf_" + maf + ".png";
UiUtils.saveImageWithPrompt(fileName, mainPanel, imagePanel);
}

View File

@ -1,8 +1,8 @@
package com.rusefi.ui.logview;
import com.opensr5.Logger;
import com.rusefi.ConsoleUI;
import com.rusefi.FileLog;
import com.rusefi.Launcher;
import com.rusefi.core.EngineState;
import com.rusefi.file.FileUtils;
import com.rusefi.ui.ChartRepository;
@ -10,7 +10,6 @@ import com.rusefi.ui.LogDownloader;
import com.rusefi.ui.UIContext;
import com.rusefi.ui.engine.EngineSnifferPanel;
import com.rusefi.ui.util.UiUtils;
import com.rusefi.io.LinkManager;
import com.rusefi.waves.EngineReport;
import javax.swing.*;
@ -22,7 +21,6 @@ import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.TreeMap;
/**
* This tab is the entry point of rusEfi own log browser
@ -39,7 +37,7 @@ public class LogViewer extends JPanel {
return pathname.getName().contains("MAIN_rfi_report");
}
};
public static final String DEFAULT_LOG_LOCATION = FileLog.DIR;
public static final String DEFAULT_LOG_LOCATION = Logger.DIR;
private final JLabel folderLabel = new JLabel();
private final JLabel fileLabel = new JLabel();
private final DefaultListModel<FileItem> fileListModel = new DefaultListModel<FileItem>();

View File

@ -16,6 +16,6 @@ class BinaryProtocolServerSandbox {
LinkManager linkManager = new LinkManager(FileLog.LOGGER);
linkManager.setConnector(LinkConnector.getDetachedConnector(state));
new BinaryProtocolServer().start(linkManager);
new BinaryProtocolServer(FileLog.LOGGER).start(linkManager);
}
}