static int sr_logv(void *cb_data, int loglevel, const char *format, va_list args) { uint64_t elapsed_us, minutes; unsigned int rest_us, seconds, microseconds; int ret; /* This specific log callback doesn't need the void pointer data. */ (void)cb_data; /* Only output messages of at least the selected loglevel(s). */ if (loglevel > cur_loglevel) return SR_OK; if (cur_loglevel >= LOGLEVEL_TIMESTAMP) { elapsed_us = g_get_monotonic_time() - sr_log_start_time; minutes = elapsed_us / G_TIME_SPAN_MINUTE; rest_us = elapsed_us % G_TIME_SPAN_MINUTE; seconds = rest_us / G_TIME_SPAN_SECOND; microseconds = rest_us % G_TIME_SPAN_SECOND; ret = g_fprintf(stderr, "sr: [%.2" PRIu64 ":%.2u.%.6u] ", minutes, seconds, microseconds); } else { ret = fputs("sr: ", stderr); } if (ret < 0 || g_vfprintf(stderr, format, args) < 0 || putc('\n', stderr) < 0) return SR_ERR; return SR_OK; }
void l_debug (const gchar * fmt, ...) { va_list argp; char timestr[100]; time_t t; if (logfile == NULL) { gchar logname[32], ologname[32]; g_snprintf (logname, 32, "server-%d.log", server_port); g_snprintf (ologname, 32, "server-%d.log.old", server_port); gchar *logpath = g_build_filename (g_get_user_data_dir (), "lyricue", logname, NULL); gchar *ologpath = g_build_filename (g_get_user_data_dir (), "lyricue", ologname, NULL); g_rename (logpath, ologpath); logfile = g_fopen (logpath, "w"); if (debugging) { g_printf ("Logging to %s\n", logpath); } } t = time (NULL); if (strftime (timestr, sizeof (timestr), "%H:%M:%S %d/%m", localtime (&t)) != 0) { if (debugging) { g_fprintf (stderr, "(%s) ", timestr); } g_fprintf (logfile, "(%s) ", timestr); } if (debugging) { // stderr va_start (argp, fmt); g_vfprintf (stderr, fmt, argp); g_fprintf (stderr, "\n"); va_end (argp); } // logfile va_start (argp, fmt); g_vfprintf (logfile, fmt, argp); g_fprintf (logfile, "\n"); va_end (argp); fflush (logfile); }
/* Print error message on stderr. */ void _warn(int line, const char *fct, const char *fmt, ...) { va_list ap; va_start(ap, fmt); g_fprintf(stderr, "W: luakit: %s:%d: ", fct, line); g_vfprintf(stderr, fmt, ap); va_end(ap); g_fprintf(stderr, "\n"); }
static void color_print(const char* color, FILE* file, const char* format, va_list args) { gboolean colors = wsh_client_has_colors(); if (colors && isatty(fileno(file))) g_fprintf(file, "%s", color); g_vfprintf(file, format, args); if (colors && isatty(fileno(file))) g_fprintf(file, "%s", "\x1b[39m"); }
/* Print error and exit with EXIT_FAILURE code. */ void _fatal(int line, const char *fct, const char *fmt, ...) { va_list ap; va_start(ap, fmt); g_fprintf(stderr, "E: luakit: %s:%d: ", fct, line); g_vfprintf(stderr, fmt, ap); va_end(ap); g_fprintf(stderr, "\n"); exit(EXIT_FAILURE); }
void test_printerr (const gchar *fmt, ...) { va_list ap; if (sz > 1) g_fprintf (stderr, "%d: ", rk); va_start (ap, fmt); g_vfprintf (stderr, fmt, ap); va_end (ap); }
/* Print debug message on stderr. */ void _debug(int line, const char *fct, const char *fmt, ...) { if (globalconf.verbose) { va_list ap; va_start(ap, fmt); g_fprintf(stderr, "D: luakit: %s:%d: ", fct, line); g_vfprintf(stderr, fmt, ap); va_end(ap); g_fprintf(stderr, "\n"); } }
void spit(const char *path, char *fmt, ...) { va_list args; va_start(args, fmt); FILE *f = g_fopen(path, "w"); if (f == NULL) fail("g_fopen", errno); g_vfprintf(f, fmt, args); fclose(f); }
/** * g_fprintf: * @file: the stream to write to. * @format: a standard printf() format string, but notice * <link linkend="string-precision">string precision pitfalls</link>. * @Varargs: the arguments to insert in the output. * * An implementation of the standard fprintf() function which supports * positional parameters, as specified in the Single Unix Specification. * * Returns: the number of bytes printed. * * Since: 2.2 **/ gint g_fprintf (FILE *file, gchar const *format, ...) { va_list args; gint retval; va_start (args, format); retval = g_vfprintf (file, format, args); va_end (args); return retval; }
void wshc_verbose_print(wshc_output_info_t* out, const gchar* format, ...) { if (out->verbose) { gboolean colors = wsh_client_has_colors(); va_list args; va_start(args, format); g_mutex_lock(out->mut); if (colors) g_printerr("\x1b[39m"); g_printerr("verbose: "); g_vfprintf(stderr, format, args); g_mutex_unlock(out->mut); va_end(args); } }
static void _debug_print(const char *file, int line, const char *function, const char *fmt, ...) { va_list ap; char *format = NULL; if (function != NULL) format = g_strdup_printf("%s:%d: %s(): %s\n", file, line, function, fmt); else format = g_strdup_printf("%s:%d: %s\n", file, line, fmt); va_start(ap, fmt); g_vfprintf(stderr, format, ap); va_end(ap); g_free(format); }
static int srd_logv(void *cb_data, int loglevel, const char *format, va_list args) { /* This specific log callback doesn't need the void pointer data. */ (void)cb_data; /* Only output messages of at least the selected loglevel(s). */ if (loglevel > cur_loglevel) return SRD_OK; if (fputs("srd: ", stderr) < 0 || g_vfprintf(stderr, format, args) < 0 || putc('\n', stderr) < 0) return SRD_ERR; return SRD_OK; }
void moto_rman_node_write(MotoRManNode *self, guint indent_num, const gchar *fmt, ...) { MotoRManNodePriv* priv = MOTO_RMAN_NODE_GET_PRIVATE(self); if(!priv->out) return; FILE* out = priv->out; GString *indent = g_string_new(""); guint i; for(i = 0; i < indent_num; ++i) g_string_append(indent, " "); g_fprintf(out, "%s", indent->str); g_string_free(indent, TRUE); va_list ap; va_start(ap, fmt); g_vfprintf(out, fmt, ap); va_end(ap); }
void vsg_packed_msg_trace (gchar *format, ...) { gdouble seconds; gulong microseconds; va_list ap; if (! _trace_active) return; _trace_file_open (); seconds = g_timer_elapsed (_timer, NULL); microseconds = (glong) (seconds * 1.e6); g_fprintf (_trace_file, "%lu: # ", microseconds); va_start (ap, format); g_vfprintf (_trace_file, format, ap); va_end (ap); g_fprintf (_trace_file, "\n"); fflush (_trace_file); }
void sydbox_access_violation(const pid_t pid, const gchar *path, const gchar *fmt, ...) { va_list args; time_t now = time(NULL); if (NULL != path) { GSList *walk = sydbox_config_get_filters(); while (NULL != walk) { gchar *pattern = (gchar *)walk->data; if (0 == fnmatch(pattern, path, FNM_PATHNAME)) { g_debug("pattern `%s' matches path `%s', ignoring the access violation", pattern, path); return; } else g_debug("pattern `%s' doesn't match path `%s'", pattern, path); walk = g_slist_next(walk); } } g_fprintf(stderr, PACKAGE "@%lu: %sAccess Violation!%s\n", now, sydbox_config_get_colourise_output() ? ANSI_MAGENTA : "", sydbox_config_get_colourise_output() ? ANSI_NORMAL : ""); g_fprintf(stderr, PACKAGE "@%lu: %sChild Process ID: %s%i%s\n", now, sydbox_config_get_colourise_output() ? ANSI_MAGENTA : "", sydbox_config_get_colourise_output() ? ANSI_DARK_MAGENTA : "", pid, sydbox_config_get_colourise_output() ? ANSI_NORMAL : ""); g_fprintf(stderr, PACKAGE "@%lu: %sReason: %s", now, sydbox_config_get_colourise_output() ? ANSI_MAGENTA : "", sydbox_config_get_colourise_output() ? ANSI_DARK_MAGENTA : ""); va_start(args, fmt); g_vfprintf(stderr, fmt, args); va_end(args); g_fprintf(stderr, "%s\n", sydbox_config_get_colourise_output() ? ANSI_NORMAL : ""); }