示例#1
0
文件: log.c 项目: Hamakor/geany
static void handler_log(const gchar *domain, GLogLevelFlags level, const gchar *msg, gpointer data)
{
	gchar *time_str;

	if (G_LIKELY(app != NULL && app->debug_mode) ||
		! ((G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE) & level))
	{
#ifdef G_OS_WIN32
		/* On Windows g_log_default_handler() is not enough, we need to print it
		 * explicitly on stderr for the console window */
		/** TODO this can be removed if/when we remove the console window on Windows */
		if (domain != NULL)
			fprintf(stderr, "%s: %s\n", domain, msg);
		else
			fprintf(stderr, "%s\n", msg);
#else
		/* print the message as usual on stdout/stderr */
		g_log_default_handler(domain, level, msg, data);
#endif
	}

	time_str = utils_get_current_time_string();

	g_string_append_printf(log_buffer, "%s: %s %s: %s\n", time_str, domain,
		get_log_prefix(level), msg);

	g_free(time_str);

	update_dialog();
}
示例#2
0
文件: log.c 项目: ikrabbe/nyx
static void
log_msg(FILE *stream, log_level_e level, const char *msg, size_t length)
{
    /* safe errno */
    int error = errno;

    time_t now = time(NULL);
    struct tm *time = localtime(&now);

    if (color)
    {
        size_t start_length;
        const char *start_color = get_log_color(level, &start_length);

        fwrite(start_color, start_length, 1, stream);
    }

    fwrite(get_log_prefix(level), 4, 1, stream);

    fprintf(stream, "%04d-%02d-%02dT%02d:%02d:%02d ",
                time->tm_year + 1900,
                time->tm_mon + 1,
                time->tm_mday,
                time->tm_hour,
                time->tm_min,
                time->tm_sec);

    fwrite(msg, length, 1, stream);

    /* errno specific handling */
    if (level & NYX_LOG_PERROR)
    {
        char buffer[512];
        char *error_msg = strerror_r(error, buffer, 511);

        fputc(':', stream);
        fputc(' ', stream);
        fwrite(error_msg, strlen(error_msg), 1, stream);
    }

    if (color)
    {
        /* write end of coloring */
        fwrite("\033[0m", 4, 1, stream);
    }

    fputc('\n', stream);

    errno = error;
}
示例#3
0
文件: log.c 项目: Benyjuice/actube
void cw_log_colored(int level, const char *format, ...)
{
	char fbuf[1024];

	sprintf(fbuf, "%s%s%s: %s%s",
		get_log_color_on(level),
		get_log_prefix(level),
		get_log_color_ontext(level),
		format,
		get_log_color_off(level)
		);
		

	va_list args;
	va_start(args, format);
	cw_log_vcb(level,fbuf,args);
	va_end(args);

}
示例#4
0
文件: genuuid.c 项目: sunny256/suuid
struct uuid_result create_and_log_uuids(const struct Options *opt)
{
	struct uuid_result retval;
	char *rcfile = NULL, *logfile = NULL;
	unsigned int i, count;
	struct Rc rc;
	struct Entry entry;
	struct Logs logs;

	assert(opt);

	logs.logfp = NULL;
	count = opt->count;
	retval.count = 0;
	memset(retval.lastuuid, 0, UUID_LENGTH + 1);
	retval.success = TRUE;
	init_xml_entry(&entry);

	/*
	 * Get information about the environment; hostname, current directory, 
	 * tty, location of rc file and log directory, etc.
	 */

	if (init_randomness() == EXIT_FAILURE) {
		retval.success = FALSE;
		goto cleanup;
	}

	rcfile = get_rcfilename(opt);
	if (read_rcfile(rcfile, &rc) == EXIT_FAILURE) {
		retval.success = FALSE;
		goto cleanup;
	}

	if (fill_entry_struct(&entry, &rc, opt) == EXIT_FAILURE) {
		retval.success = FALSE;
		goto cleanup;
	}

	logfile = get_log_prefix(&rc, opt, ".xml");
	if (!logfile) {
		retval.success = FALSE;
		goto cleanup;
	}

	signal(SIGHUP, sighandler);
	signal(SIGINT, sighandler);
	signal(SIGQUIT, sighandler);
	signal(SIGPIPE, sighandler);
	signal(SIGTERM, sighandler);

	/*
	 * Open the log file. If it's missing, create it.
	 */

	logs.logfp = open_logfile(logfile);
	if (!logs.logfp) {
		retval.success = FALSE;
		goto cleanup;
	}

	/*
	 * Generate the UUIDs and write them to the log file.
	 */

	if (opt->uuid)
		count = 1;
	for (i = 0; i < count; i++) {
		if (!process_uuid(&logs, &rc, opt, &entry)) {
			retval.success = FALSE;
			goto cleanup;
		}
		retval.count++;
		if (should_terminate)
			break;
	}
	if (valid_uuid(entry.uuid, TRUE))
		strncpy(retval.lastuuid, entry.uuid, UUID_LENGTH + 1);

	/*
	 * Check that the correct amount of UUIDs were created.
	 */

	if (retval.count < opt->count)
		fprintf(stderr, "%s: Generated only %u of %u UUIDs\n",
		                progname, retval.count, opt->count);

	/*
	 * Close up the shop and go home.
	 */

cleanup:
	if (logs.logfp && (close_logfile(logs.logfp) == EXIT_FAILURE))
		retval.success = FALSE;

	free(logfile);
	free_sess(&entry);
	free_tags(&entry);
	free(rc.uuidcmd);
	free(rc.macaddr);
	free(rc.hostname);
	free(entry.txt);
	free(entry.date);
	free(entry.cwd);
	free(rcfile);

	return retval;
}