aboutsummaryrefslogtreecommitdiff
path: root/src/libeinfo.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-04-25 12:30:24 +0000
committerRoy Marples <roy@marples.name>2007-04-25 12:30:24 +0000
commitdfc208bd25288dd09d531f3e0665274bb9cf2998 (patch)
treee3253e1b287969e4abf72441894b53f17bbdc49e /src/libeinfo.c
parentae32cbdd4b863fbe707981f85c19e04b1faecf6c (diff)
We now have an alternative to buffering stdout and stderr.
RC_PREFIX="yes" will put the service name as a prefix to all output made by the service. Thanks to Ciaran McCreesh for the idea.
Diffstat (limited to 'src/libeinfo.c')
-rw-r--r--src/libeinfo.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/libeinfo.c b/src/libeinfo.c
index a6c0a2a1..4b2f9589 100644
--- a/src/libeinfo.c
+++ b/src/libeinfo.c
@@ -125,6 +125,9 @@ static int stdfd[2] = {-1, -1};
static FILE *ebfp = NULL;
static char ebfile[PATH_MAX] = { '\0' };
+/* A pointer to a string to prefix to einfo/ewarn/eerror messages */
+static const char *_eprefix = NULL;
+
static bool is_env (const char *var, const char *val)
{
char *v;
@@ -184,6 +187,10 @@ static int get_term_columns (void)
return (DEFAULT_COLS);
}
+void eprefix (const char *prefix) {
+ _eprefix = prefix;
+}
+
void ebuffer (const char *file)
{
/* Don't ebuffer if we don't have a file or we already are */
@@ -379,16 +386,18 @@ const char *ecolor (einfo_color_t color) {
hidden_def(ecolor)
#define EINFOVN(_file, _color) \
-fprintf (_file, " %s*%s ", ecolor (_color), ecolor (ecolor_normal)); \
-retval += _eindent (_file); \
+ if (_eprefix) \
+ fprintf (_file, "%s%s%s|", ecolor (_color), _eprefix, ecolor (ecolor_normal)); \
+ fprintf (_file, " %s*%s ", ecolor (_color), ecolor (ecolor_normal)); \
+ retval += _eindent (_file); \
{ \
va_list _ap; \
va_copy (_ap, ap); \
retval += vfprintf (_file, fmt, _ap) + 3; \
va_end (_ap); \
} \
-if (colour_terminal ()) \
-fprintf (_file, ECOLOR_FLUSH);
+ if (colour_terminal ()) \
+ fprintf (_file, ECOLOR_FLUSH);
static int _einfovn (const char *fmt, va_list ap)
{