mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
добавление логирования
This commit is contained in:
@@ -4,29 +4,67 @@
|
||||
class Loging : public IoTItem {
|
||||
private:
|
||||
String logval;
|
||||
String id;
|
||||
String fileName = "";
|
||||
|
||||
public:
|
||||
Loging(String parameters) : IoTItem(parameters) {
|
||||
jsonRead(parameters, F("logid"), logval);
|
||||
jsonRead(parameters, F("id"), id);
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
String value = getItemValue(logval);
|
||||
size_t lines = 0;
|
||||
//если задано не правильное logid величины для логгирования
|
||||
if (value == "") {
|
||||
SerialPrint("E", F("Logging"), F("no value set"));
|
||||
SerialPrint("E", F("Loging"), F("no value set"));
|
||||
} else {
|
||||
//если время было получено из интернета
|
||||
if (isTimeSynch) {
|
||||
regEvent(value, "Logging");
|
||||
String logData = String(unixTime) + " " + value;
|
||||
addFileLn("/log.txt", logData);
|
||||
regEvent(value, "Loging");
|
||||
String logData = String(unixTimeShort) + " " + value;
|
||||
|
||||
static bool firstTime = true;
|
||||
//если зашли сюда первый раз то создаем файл с именем id-timestamp
|
||||
if (firstTime) {
|
||||
firstTime = false;
|
||||
createFileWithIdDatatimeName(logData);
|
||||
//если 2 ой раз и последующие разы
|
||||
} else {
|
||||
lines = countLines(fileName);
|
||||
if (lines <= 255) {
|
||||
addFileLn(fileName, logData);
|
||||
} else {
|
||||
createFileWithIdDatatimeName(logData);
|
||||
}
|
||||
}
|
||||
SerialPrint("i", F("Loging"), "loging in file (" + String(lines) + ") http://" + WiFi.localIP().toString() + fileName);
|
||||
|
||||
} else {
|
||||
SerialPrint("E", F("Logging"), F("cant logging - no time Synch"));
|
||||
SerialPrint("E", F("Loging"), F("Сant loging - time not synchronized"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createFileWithIdDatatimeName(String &logData) {
|
||||
fileName = "/logs/" + id + "-" + String(unixTimeShort) + ".txt";
|
||||
addFileLn(fileName, logData);
|
||||
SerialPrint("i", F("Loging"), "file created http://" + WiFi.localIP().toString() + fileName);
|
||||
}
|
||||
|
||||
void cleanLog() {
|
||||
String directory = "logs/" + id;
|
||||
auto dir = FileFS.openDir(directory);
|
||||
while (dir.next()) {
|
||||
String fname = dir.fileName();
|
||||
removeFile(directory + "/" + fname);
|
||||
SerialPrint("I", "Loging", fname + " deleted");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void* getAPI_Loging(String subtype, String param) {
|
||||
void *getAPI_Loging(String subtype, String param) {
|
||||
if (subtype == F("Loging")) {
|
||||
return new Loging(param);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user