mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-25 03:32:16 +00:00
Option for setting the log level at rascsi startup, improved device file support (#121)
* Added option for setting log level at rascsi startup * Report an error if only an extension without a basename is provided * Improved device file support
This commit is contained in:
parent
9898cb1a13
commit
da70ce7055
@ -30,6 +30,10 @@
|
|||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||||
#include <spdlog/async.h>
|
#include <spdlog/async.h>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
@ -548,7 +552,7 @@ BOOL ProcessCmd(FILE *fp, int id, int un, int cmd, int type, char *file)
|
|||||||
// break;
|
// break;
|
||||||
case rasctl_dev_daynaport: // DaynaPort SCSI Link
|
case rasctl_dev_daynaport: // DaynaPort SCSI Link
|
||||||
pUnit = new SCSIDaynaPort();
|
pUnit = new SCSIDaynaPort();
|
||||||
LOGTRACE("Done creating SCSIDayanPort");
|
LOGTRACE("Done creating SCSIDaynaPort");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FPRT(fp, "Error : Invalid device type\n");
|
FPRT(fp, "Error : Invalid device type\n");
|
||||||
@ -558,8 +562,12 @@ BOOL ProcessCmd(FILE *fp, int id, int un, int cmd, int type, char *file)
|
|||||||
|
|
||||||
// drive checks files
|
// drive checks files
|
||||||
if (type <= rasctl_dev_scsi_hd || ((type <= rasctl_dev_cd || type == rasctl_dev_daynaport) && xstrcasecmp(file, "-") != 0)) {
|
if (type <= rasctl_dev_scsi_hd || ((type <= rasctl_dev_cd || type == rasctl_dev_daynaport) && xstrcasecmp(file, "-") != 0)) {
|
||||||
|
// Strip the image file extension from device file names, so that device files can be used as drive images
|
||||||
|
string f = file;
|
||||||
|
string effective_file = f.find("/dev/") ? f : f.substr(0, f.length() - 4);
|
||||||
|
|
||||||
// Set the Path
|
// Set the Path
|
||||||
filepath.SetPath(file);
|
filepath.SetPath(effective_file.c_str());
|
||||||
|
|
||||||
// Open the file path
|
// Open the file path
|
||||||
if (!pUnit->Open(filepath)) {
|
if (!pUnit->Open(filepath)) {
|
||||||
@ -678,7 +686,7 @@ BOOL ProcessCmd(FILE *fp, int id, int un, int cmd, int type, char *file)
|
|||||||
bool has_suffix(const char* string, const char* suffix) {
|
bool has_suffix(const char* string, const char* suffix) {
|
||||||
int string_len = strlen(string);
|
int string_len = strlen(string);
|
||||||
int suffix_len = strlen(suffix);
|
int suffix_len = strlen(suffix);
|
||||||
return (string_len >= suffix_len)
|
return (string_len > suffix_len)
|
||||||
&& (xstrcasecmp(string + (string_len - suffix_len), suffix) == 0);
|
&& (xstrcasecmp(string + (string_len - suffix_len), suffix) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -872,9 +880,10 @@ bool ParseArgument(int argc, char* argv[])
|
|||||||
int id = -1;
|
int id = -1;
|
||||||
bool is_sasi = false;
|
bool is_sasi = false;
|
||||||
int max_id = 7;
|
int max_id = 7;
|
||||||
|
string log_level = "trace";
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "-IiHhD:d:")) != -1) {
|
while ((opt = getopt(argc, argv, "-IiHhL:l:D:d:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'I':
|
case 'I':
|
||||||
case 'i':
|
case 'i':
|
||||||
@ -890,6 +899,11 @@ bool ParseArgument(int argc, char* argv[])
|
|||||||
id = -1;
|
id = -1;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
case 'L':
|
||||||
|
case 'l':
|
||||||
|
log_level = optarg;
|
||||||
|
continue;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
case 'd': {
|
case 'd': {
|
||||||
char* end;
|
char* end;
|
||||||
@ -935,9 +949,9 @@ bool ParseArgument(int argc, char* argv[])
|
|||||||
} else if (xstrcasecmp(path, "daynaport") == 0) {
|
} else if (xstrcasecmp(path, "daynaport") == 0) {
|
||||||
type = rasctl_dev_daynaport;
|
type = rasctl_dev_daynaport;
|
||||||
} else {
|
} else {
|
||||||
// Cannot determine the file type
|
// Cannot determine the file type or the basename is missing
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s: unknown file extension\n", path);
|
"%s: unknown file extension or basename is missing\n", path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -954,6 +968,32 @@ bool ParseArgument(int argc, char* argv[])
|
|||||||
id = -1;
|
id = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Evaluate log level
|
||||||
|
if (log_level == "trace") {
|
||||||
|
spdlog::set_level(spdlog::level::trace);
|
||||||
|
}
|
||||||
|
else if (log_level == "debug") {
|
||||||
|
spdlog::set_level(spdlog::level::debug);
|
||||||
|
}
|
||||||
|
else if (log_level == "info") {
|
||||||
|
spdlog::set_level(spdlog::level::info);
|
||||||
|
}
|
||||||
|
else if (log_level == "warn") {
|
||||||
|
spdlog::set_level(spdlog::level::warn);
|
||||||
|
}
|
||||||
|
else if (log_level == "err") {
|
||||||
|
spdlog::set_level(spdlog::level::err);
|
||||||
|
}
|
||||||
|
else if (log_level == "critical") {
|
||||||
|
spdlog::set_level(spdlog::level::critical);
|
||||||
|
}
|
||||||
|
else if (log_level == "off") {
|
||||||
|
spdlog::set_level(spdlog::level::off);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cerr << "Invalid log level '" << log_level << "', falling back to 'trace'" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
// Display the device list
|
// Display the device list
|
||||||
ListDevice(stdout);
|
ListDevice(stdout);
|
||||||
return true;
|
return true;
|
||||||
@ -1127,11 +1167,10 @@ int main(int argc, char* argv[])
|
|||||||
struct sched_param schparam;
|
struct sched_param schparam;
|
||||||
#endif // BAREMETAL
|
#endif // BAREMETAL
|
||||||
|
|
||||||
spdlog::set_level(spdlog::level::trace);
|
spdlog::set_level(spdlog::level::trace);
|
||||||
// Create a thread-safe stdout logger to process the log messages
|
// Create a thread-safe stdout logger to process the log messages
|
||||||
auto logger = spdlog::stdout_color_mt("rascsi stdout logger");
|
auto logger = spdlog::stdout_color_mt("rascsi stdout logger");
|
||||||
|
|
||||||
LOGTRACE("Entering the function %s with %d arguments", __PRETTY_FUNCTION__, argc);
|
|
||||||
// Output the Banner
|
// Output the Banner
|
||||||
Banner(argc, argv);
|
Banner(argc, argv);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user