Ejemplo n.º 1
0
/*
 * Print a message and return to caller.
 * Caller specifies "errnoflag".
 */
static void err_doit( int fd, int errnoflag, const char *fmt, va_list ap )
{
    int errno_save;
    char buf[MAXLINE];

    errno_save = errno;         /* value caller might want printed   */
    strcpy( buf, err_tstamp() );  /* prepend a message with time stamp */
    vsprintf( buf + strlen( buf ), fmt, ap );
    if ( errnoflag )
        sprintf( buf + strlen( buf ), ": %s\n", strerror( errno_save ) );
    else
        strcat( buf, "\n" );
    write( fd, buf, strlen( buf ) );
    errno = errno_save;
}
Ejemplo n.º 2
0
/**
 * 打印错误文字消息于指定 fd 上,
 * 随后返回调用者
 */
static void err_doit(int fd, int errnoflag, const char *fmt, va_list ap)
{
  int errno_save;
  char buf[512];

  errno_save = errno;
  strcpy(buf, err_tstamp());
  vsprintf(buf + strlen(buf), fmt, ap);

  if (errnoflag)
    sprintf(buf + strlen(buf), fmt, ap);
  else
    strcat(buf, "\n");

  write(fd, buf, strlen(buf));
  errno = errno_save;
}
Ejemplo n.º 3
0
void
hoxLog(enum hoxLogLevel level, const char *fmt, ...)
{
    static const char *levels[] = { "FATAL", "SYS_FATAL",
                                    "ERROR", "SYS_ERROR",
                                    "WARN",  "SYS_WARN",
                                    "INFO",
                                    "DEBUG"
                                  };

    int errno_save;
    char buf[MAXLINE];

    int errnoflag = (   level == LOG_SYS_FATAL
                     || level == LOG_SYS_ERROR
                     || level == LOG_SYS_WARN )
                    ? 1 : 0;

    int fd = s_errfd;     // TODO: Defined in main.cpp
    va_list ap;

    va_start( ap, fmt );

    errno_save = errno;         /* value caller might want printed   */
    snprintf(buf, sizeof(buf), "%s%s: ", err_tstamp(), levels[level]);
    vsprintf( buf + strlen( buf ), fmt, ap );
    if ( errnoflag )
    {
        sprintf( buf + strlen( buf ), ": %s\n", strerror( errno_save ) );
    }
    else
    {
        strcat( buf, "\n" );
    }
    write( fd, buf, strlen( buf ) );
    errno = errno_save;

    va_end( ap );
}