Skip to content

Commit

Permalink
[Feature] - Addition of logging activity simulated command filter option
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Apr 22, 2024
1 parent f5407c5 commit 1d084a1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Configures the logging, tracking activity of relevant commands, and console outp
| **fiatConversion.rate** | Duration string (ex: `8h`) | Minimum duration between two consecutive requests of the same fiat conversion |
| **log.activityTracking.commandTypes** | Array of strings (ex: `["Buy", "Sell"]`) | Array of command types whose output will be stored to activity history files. |
| **log.activityTracking.dateFileNameFormat** | String (ex: `%Y-%m` for month split) | Defines the date string format suffix used by activity history files. The string should be compatible with [std::strftime](https://en.cppreference.com/w/cpp/chrono/c/strftime). Old data will never be clean-up by `coincenter` (as it may contain important data). User should manage the clean-up / storage. |
| **log.activityTracking.withSimulatedCommands** | Boolean | When some commands are launched in simulated mode (trades, withdraw for instance), they will be logged if `true`. |
| **log.consoleLevel** | String | Defines the log level for standard output. Can be {'off', 'critical', 'error', 'warning', 'info', 'debug', 'trace'} |
| **log.fileLevel** | String | Defines the log level in files. Can be {'off', 'critical', 'error', 'warning', 'info', 'debug', 'trace'} |
| **log.maxFileSize** | String (ex: `5Mi` for 5 Megabytes) | Defines in bytes the maximum logging file size. A string representation of an integral, possibly with one suffix ending such as k, M, G, T (1k multipliers) or Ki, Mi, Gi, Ti (1024 multipliers) are supported. |
Expand Down
2 changes: 1 addition & 1 deletion src/engine/include/queryresultprinter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class QueryResultPrinter {

void printJson(const json &jsonData) const;

void logActivity(CoincenterCommandType commandType, const json &data) const;
void logActivity(CoincenterCommandType commandType, const json &data, bool isSimulationMode = false) const;

const LoggingInfo &_loggingInfo;
std::ostream *_pOs = nullptr;
Expand Down
11 changes: 7 additions & 4 deletions src/engine/src/queryresultprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ void QueryResultPrinter::printTrades(const TradeResultPerExchange &tradeResultPe
case ApiOutputType::kNoPrint:
break;
}
logActivity(commandType, jsonData);
logActivity(commandType, jsonData, tradeOptions.isSimulation());
}

void QueryResultPrinter::printClosedOrders(const ClosedOrdersPerExchange &closedOrdersPerExchange,
Expand Down Expand Up @@ -1414,7 +1414,8 @@ void QueryResultPrinter::printWithdraw(const DeliveredWithdrawInfoWithExchanges
case ApiOutputType::kNoPrint:
break;
}
logActivity(CoincenterCommandType::kWithdrawApply, jsonData);
logActivity(CoincenterCommandType::kWithdrawApply, jsonData,
withdrawOptions.mode() == WithdrawOptions::Mode::kSimulation);
}

void QueryResultPrinter::printDustSweeper(
Expand Down Expand Up @@ -1474,8 +1475,10 @@ void QueryResultPrinter::printJson(const json &jsonData) const {
}
}

void QueryResultPrinter::logActivity(CoincenterCommandType commandType, const json &jsonData) const {
if (_loggingInfo.isCommandTypeTracked(commandType)) {
void QueryResultPrinter::logActivity(CoincenterCommandType commandType, const json &jsonData,
bool isSimulationMode) const {
if (_loggingInfo.isCommandTypeTracked(commandType) &&
(!isSimulationMode || _loggingInfo.alsoLogActivityForSimulatedCommands())) {
File activityFile = _loggingInfo.getActivityFile();
activityFile.write(jsonData, Writer::Mode::Append);
}
Expand Down
3 changes: 2 additions & 1 deletion src/objects/include/generalconfigdefault.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct GeneralConfigDefault {
"Withdraw",
"DustSweeper"
],
"dateFileNameFormat": "%Y-%m"
"dateFileNameFormat": "%Y-%m",
"withSimulatedCommands": false
},
"consoleLevel": "info",
"fileLevel": "debug",
Expand Down
3 changes: 3 additions & 0 deletions src/objects/include/logginginfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class LoggingInfo {

File getActivityFile() const;

bool alsoLogActivityForSimulatedCommands() const { return _alsoLogActivityForSimulatedCommands; }

private:
void createLoggers();

Expand All @@ -66,6 +68,7 @@ class LoggingInfo {
int8_t _logLevelConsolePos = PosFromLevel(log::level::info);
int8_t _logLevelFilePos = PosFromLevel(log::level::off);
bool _destroyLoggers = false;
bool _alsoLogActivityForSimulatedCommands = false;
};

} // namespace cct
4 changes: 3 additions & 1 deletion src/objects/src/logginginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ LoggingInfo::LoggingInfo(WithLoggersCreation withLoggersCreation, std::string_vi
[](const json &elem) { return CoincenterCommandTypeFromString(elem.get<std::string_view>()); });

_dateFormatStrActivityFiles = activityTrackingPart["dateFileNameFormat"];
_alsoLogActivityForSimulatedCommands = activityTrackingPart["withSimulatedCommands"].get<bool>();
}

LoggingInfo::LoggingInfo(LoggingInfo &&loggingInfo) noexcept
Expand All @@ -61,7 +62,8 @@ LoggingInfo::LoggingInfo(LoggingInfo &&loggingInfo) noexcept
_maxNbLogFiles(loggingInfo._maxNbLogFiles),
_logLevelConsolePos(loggingInfo._logLevelConsolePos),
_logLevelFilePos(loggingInfo._logLevelFilePos),
_destroyLoggers(std::exchange(loggingInfo._destroyLoggers, false)) {}
_destroyLoggers(std::exchange(loggingInfo._destroyLoggers, false)),
_alsoLogActivityForSimulatedCommands(loggingInfo._alsoLogActivityForSimulatedCommands) {}

LoggingInfo::~LoggingInfo() {
if (_destroyLoggers) {
Expand Down

0 comments on commit 1d084a1

Please sign in to comment.