mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-22 04:24:19 +00:00
Add log-file option to automatically redirect stderr to a file
From bfgminer b0240dd004
This commit is contained in:
parent
0bd7a9ff63
commit
4a9ee47cd9
1
compat.h
1
compat.h
@ -4,6 +4,7 @@
|
||||
#ifdef WIN32
|
||||
#include "config.h"
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/time.h>
|
||||
|
@ -465,6 +465,7 @@ sgminer 4.2.1-116-g2e8b-dirty
|
||||
* [incognito](#incognito)
|
||||
* [kernel-path](#kernel-path)
|
||||
* [log](#log)
|
||||
* [log-file](#log-file)
|
||||
* [log-show-date](#log-show-date)
|
||||
* [lowmem](#lowmem)
|
||||
* [monitor](#monitor)
|
||||
@ -1973,6 +1974,22 @@ Set the interval in seconds between log outputs.
|
||||
|
||||
[Top](#configuration-and-command-line-options) :: [Config-file and CLI options](#config-file-and-cli-options) :: [Miscellaneous Options](#miscellaneous-options)
|
||||
|
||||
### log-file
|
||||
|
||||
Log stderr to file.
|
||||
|
||||
*Available*: Global
|
||||
|
||||
*Config File Syntax:* `"log-file":"<path>"`
|
||||
|
||||
*Command Line Syntax:* `--log-file <path>`
|
||||
|
||||
*Argument:* `path` Path to log file, or FD number, or `-` to redirect to stdout.
|
||||
|
||||
*Default:* will log to stderr
|
||||
|
||||
[Top](#configuration-and-command-line-options) :: [Config-file and CLI options](#config-file-and-cli-options) :: [Miscellaneous Options](#miscellaneous-options)
|
||||
|
||||
### log-show-date
|
||||
|
||||
Show a timestamp on every log line.
|
||||
|
33
sgminer.c
33
sgminer.c
@ -1116,6 +1116,36 @@ static char *set_schedtime(const char *arg, struct schedtime *st)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *set_log_file(char *arg)
|
||||
{
|
||||
char *r = "";
|
||||
long int i = strtol(arg, &r, 10);
|
||||
int fd, stderr_fd = fileno(stderr);
|
||||
|
||||
if ((!*r) && i >= 0 && i <= INT_MAX)
|
||||
fd = i;
|
||||
else
|
||||
if (!strcmp(arg, "-"))
|
||||
{
|
||||
fd = fileno(stdout);
|
||||
if (unlikely(fd == -1))
|
||||
return "Standard output missing for log-file";
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = open(arg, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
|
||||
if (unlikely(fd == -1))
|
||||
return "Failed to open %s for log-file";
|
||||
}
|
||||
|
||||
close(stderr_fd);
|
||||
if (unlikely(-1 == dup2(fd, stderr_fd)))
|
||||
return "Failed to dup2 for log-file";
|
||||
close(fd);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char* set_sharelog(char *arg)
|
||||
{
|
||||
char *r = "";
|
||||
@ -1415,6 +1445,9 @@ struct opt_table opt_config_table[] = {
|
||||
OPT_WITH_ARG("--log|-l",
|
||||
set_int_0_to_9999, opt_show_intval, &opt_log_interval,
|
||||
"Interval in seconds between log output"),
|
||||
OPT_WITH_ARG("--log-file|-L",
|
||||
set_log_file, NULL, NULL,
|
||||
"Log stderr to file"),
|
||||
OPT_WITHOUT_ARG("--log-show-date|-L",
|
||||
opt_set_bool, &opt_log_show_date,
|
||||
"Show date on every log line"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user