Skip to content

Commit

Permalink
Add --log-file option which redirects stderr to a file, but valid any…
Browse files Browse the repository at this point in the history
…where in the commandline or config file
  • Loading branch information
luke-jr committed Jul 7, 2013
1 parent 43c1d26 commit b0240dd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Options for both config file and command line:
--kernel-path|-K <arg> Specify a path to where bitstream and kernel files are (default: "/usr/local/bin")
--load-balance Change multipool strategy from failover to efficiency based balance
--log|-l <arg> Interval in seconds between log output (default: 5)
--log-file|-L <arg> Append log file for output messages
--log-microseconds Include microseconds in log output
--monitor|-m <arg> Use custom pipe cmd for output messages
--net-delay Impose small delays in networking to not overload slow routers
Expand Down
1 change: 1 addition & 0 deletions compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#ifdef WIN32
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include <pthread.h>
#include <sys/time.h>
Expand Down
37 changes: 37 additions & 0 deletions miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,37 @@ 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 = "";
Expand Down Expand Up @@ -1392,6 +1423,12 @@ static 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,
"Append log file for output messages"),
OPT_WITH_ARG("--logfile",
set_log_file, NULL, NULL,
opt_hidden),
OPT_WITHOUT_ARG("--log-microseconds",
opt_set_bool, &opt_log_microseconds,
"Include microseconds in log output"),
Expand Down

0 comments on commit b0240dd

Please sign in to comment.