Beispiel #1
0
void log_write_rec(LOG_REC *log, const char *str, int level)
{
        char *colorstr;
	struct tm *tm;
	time_t now;
	int hour, day;

	g_return_if_fail(log != NULL);
	g_return_if_fail(str != NULL);

	if (log->handle == -1)
		return;

	now = time(NULL);
	tm = localtime(&now);
	hour = tm->tm_hour;
	day = tm->tm_mday;

	tm = localtime(&log->last);
	day -= tm->tm_mday; /* tm breaks in log_rotate_check() .. */
	if (tm->tm_hour != hour) {
		/* hour changed, check if we need to rotate log file */
                log_rotate_check(log);
	}

	if (day != 0) {
		/* day changed */
		log_write_timestamp(log->handle,
				    settings_get_str("log_day_changed"),
				    "\n", now);
	}

	log->last = now;

	if (log->colorizer == NULL)
		colorstr = NULL;
        else
                str = colorstr = log->colorizer(str);

        if ((level & MSGLEVEL_LASTLOG) == 0)
		log_write_timestamp(log->handle, log_timestamp, str, now);
	else
		write_buffer(log->handle, str, strlen(str));
	write_buffer(log->handle, "\n", 1);

	signal_emit("log written", 2, log, str);

        g_free_not_null(colorstr);
}
Beispiel #2
0
int log_start_logging(LOG_REC *log)
{
	char *dir;

	g_return_val_if_fail(log != NULL, FALSE);

	if (log->handle != -1)
		return TRUE;

	/* Append/create log file */
	g_free_not_null(log->real_fname);
	log->real_fname = log_filename(log);

	if (log->real_fname != NULL &&
	    strcmp(log->real_fname, log->fname) != 0) {
		/* path may contain variables (%time, $vars),
		   make sure the directory is created */
		dir = g_dirname(log->real_fname);
		mkpath(dir, log_dir_create_mode);
		g_free(dir);
	}

	log->handle = log->real_fname == NULL ? -1 :
		open(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
		     log_file_create_mode);
	if (log->handle == -1) {
		signal_emit("log create failed", 1, log);
		log->failed = TRUE;
		return FALSE;
	}
#ifdef HAVE_FCNTL
        memset(&lock, 0, sizeof(lock));
	lock.l_type = F_WRLCK;
	if (fcntl(log->handle, F_SETLK, &lock) == -1 && errno == EACCES) {
		close(log->handle);
		log->handle = -1;
		signal_emit("log locked", 1, log);
		log->failed = TRUE;
		return FALSE;
	}
#endif
	lseek(log->handle, 0, SEEK_END);

	log->opened = log->last = time(NULL);
	log_write_timestamp(log->handle,
			    settings_get_str("log_open_string"),
			    "\n", log->last);

	signal_emit("log started", 1, log);
	log->failed = FALSE;
	return TRUE;
}
Beispiel #3
0
int main( int argc, char ** argv){
    log_and_screen_printf("Demultiplexer\n\n");
    log_and_screen_printf(SVN_VERSION);
	log_and_screen_printf(SVN_COMMIT_DATE);
	log_and_screen_printf("Compiled on %s at %s \n\n", __DATE__, __TIME__);
    if (argc < 2) {
        print_help();
    }
    log_write_timestamp(1);
    if (argc == 0) {
        print_help();
    }
    DemultiplexerCmdLine cmd = parse_args(argc, argv);
    FILE * in = stdin;
    if (cmd.input_reads != NULL) {
        in = fopen(cmd.input_reads, "r");
        if(in == NULL){
			log_and_screen_printf("Unable to open file %s\n", cmd.input_reads);
			exit(-1);
		}
    }
    Sequence * seq = sequence_new(cmd.max_read_length, cmd.max_name_length, 33);
    seq->header = new_sequence_header(CASAVA_1_8);
    header_function * f = (header_function *) seq->header;
    char * index = f->get_index(seq);
    size_t prefix_length = strlen(cmd.output_folder);
    char * output_file = calloc(prefix_length + MAX_FIELD_SIZE + 1, sizeof(char *));
    char * index_pointer = output_file + prefix_length;
    strcpy(output_file, cmd.output_folder);
    printf("prefix: %s\n", output_file);
    while (read_sequence_from_fastq(in, seq, cmd.max_read_length)) {
        strcpy(index_pointer, index);
//     printf("index: %s\n new output: %s\n", index, output_file);
        append_sequence(output_file, seq, FASTQ);
    }
    
    if (in != stdin) {
        fclose(in);
    }
    
    
    
    
    return 0;
}
Beispiel #4
0
void log_stop_logging(LOG_REC *log)
{
	g_return_if_fail(log != NULL);

	if (log->handle == -1)
		return;

	signal_emit("log stopped", 1, log);

	log_write_timestamp(log->handle,
			    settings_get_str("log_close_string"),
			    "\n", time(NULL));

#ifdef HAVE_FCNTL
        memset(&lock, 0, sizeof(lock));
	lock.l_type = F_UNLCK;
	fcntl(log->handle, F_SETLK, &lock);
#endif

	write_buffer_flush();
	close(log->handle);
	log->handle = -1;
}