Skip to content

Add possibility to define "one" log file name #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add custom log file name function in command line via -f
  • Loading branch information
aw-tech committed Jul 25, 2016
commit 5d94e216a5c37c4444f361bc75cf0d93ee596b8e
23 changes: 23 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
strlcpy (p_misc_config->gpsnmea_port, "", sizeof(p_misc_config->gpsnmea_port));
strlcpy (p_misc_config->nmea_port, "", sizeof(p_misc_config->nmea_port));
strlcpy (p_misc_config->logdir, "", sizeof(p_misc_config->logdir));
strlcpy (p_misc_config->logfilename, "", sizeof(p_misc_config->logfilename));


/*
Expand Down Expand Up @@ -3863,6 +3864,28 @@ void config_init (char *fname, struct audio_s *p_audio_config,
}
}


/*
* LOGFILENAME - Log file name.
*/
else if (strcasecmp(t, "logfilename") == 0) {
t = split(NULL,0);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: Missing name for LogFileName on line %d.\n", line);
continue;
}
else {
strlcpy (p_misc_config->logfilename, t, sizeof(p_misc_config->logfilename));
}
t = split(NULL,0);
if (t != NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: LOGFILE on line %d should have logfile name and nothing more.\n", line);
}
}


/*
* BEACON channel delay every message
*
Expand Down
2 changes: 2 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct misc_config_s {

char logdir[80]; /* Directory for saving activity logs. */

char logfilename[80]; /* File name for saving activity logs. */

int sb_configured; /* TRUE if SmartBeaconing is configured. */
int sb_fast_speed; /* MPH */
int sb_fast_rate; /* seconds */
Expand Down
17 changes: 15 additions & 2 deletions direwolf.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ int main (int argc, char *argv[])
int r_opt = 0, n_opt = 0, b_opt = 0, B_opt = 0, D_opt = 0; /* Command line options. */
char P_opt[16];
char l_opt[80];
char f_opt[80];
char input_file[80];

int t_opt = 1; /* Text color option. */
Expand All @@ -194,6 +195,7 @@ int main (int argc, char *argv[])
#endif

strlcpy(l_opt, "", sizeof(l_opt));
strlcpy(f_opt, "", sizeof(f_opt));
strlcpy(P_opt, "", sizeof(P_opt));

#if __WIN32__
Expand Down Expand Up @@ -322,7 +324,7 @@ int main (int argc, char *argv[])

/* ':' following option character means arg is required. */

c = getopt_long(argc, argv, "P:B:D:c:pxr:b:n:d:q:t:Ul:Sa:",
c = getopt_long(argc, argv, "P:B:D:c:pxr:b:n:d:q:t:Ul:Sa:Uf:",
long_options, &option_index);
if (c == -1)
break;
Expand Down Expand Up @@ -501,6 +503,11 @@ int main (int argc, char *argv[])
strlcpy (l_opt, optarg, sizeof(l_opt));
break;

case 'f': /* -f for log file name */

strlcpy (f_opt, optarg, sizeof(f_opt));
break;

case 'S': /* Print symbol tables and exit. */

symbols_init ();
Expand Down Expand Up @@ -594,6 +601,11 @@ int main (int argc, char *argv[])
strlcpy (misc_config.logdir, l_opt, sizeof(misc_config.logdir));
}

if (strlen(f_opt) > 0) {
strlcpy (misc_config.logfilename, f_opt, sizeof(misc_config.logfilename));
}


misc_config.enable_kiss_pt = enable_pseudo_terminal;

if (strlen(input_file) > 0) {
Expand Down Expand Up @@ -711,7 +723,7 @@ int main (int argc, char *argv[])
* log the tracker beacon transmissions with fake channel 999.
*/

log_init(misc_config.logdir);
log_init(misc_config.logdir, misc_config.logfilename);
beacon_init (&audio_config, &misc_config);


Expand Down Expand Up @@ -1062,6 +1074,7 @@ static void usage (char **argv)
dw_printf ("Options:\n");
dw_printf (" -c fname Configuration file name.\n");
dw_printf (" -l logdir Directory name for log files. Use . for current.\n");
dw_printf (" -f logname Name for log file. \n");
dw_printf (" -r n Audio sample rate, per sec.\n");
dw_printf (" -n n Number of audio channels, 1 or 2.\n");
dw_printf (" -b n Bits per audio sample, 8 or 16.\n");
Expand Down
13 changes: 12 additions & 1 deletion log.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ static void quote_for_csv (char *out, size_t outsize, const char *in) {
static char g_log_dir[80];
static FILE *g_log_fp;
static char g_open_fname[20];
static char g_logfilename[80];


void log_init (char *path)
void log_init (char *path, char *logfilename)
{
struct stat st;

Expand All @@ -118,6 +119,11 @@ void log_init (char *path)
return;
}

if (strlen(logfilename) != 0) {
strlcpy (g_logfilename, logfilename, sizeof(g_logfilename));
}


if (stat(path,&st) == 0) {
// Exists, but is it a directory?
if (S_ISDIR(st.st_mode)) {
Expand Down Expand Up @@ -191,7 +197,12 @@ void log_write (int chan, decode_aprs_t *A, packet_t pp, alevel_t alevel, retry_

// Microsoft doesn't recognize %F as equivalent to %Y-%m-%d

if (strlen(g_logfilename) != 0) {
strftime (fname, sizeof(fname), g_logfilename, &tm);
}
else {
strftime (fname, sizeof(fname), "%Y-%m-%d.log", &tm);
}

// Close current file if name has changed

Expand Down
4 changes: 2 additions & 2 deletions log.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@



void log_init (char *path);
void log_init (char *path, char *logfilename);

void log_write (int chan, decode_aprs_t *A, packet_t pp, alevel_t alevel, retry_t retries);

void log_term (void);
void log_term (void);