source: trunk/packages/vizservers/vtkvis/Trace.cpp @ 3177

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (C) 2004-2012  HUBzero Foundation, LLC
4 *
5 * Author: George A. Howlett <gah@purdue.edu>
6 */
7
8#include <cstdio>
9#include <cstdarg>
10#include <cstring>
11#include <syslog.h>
12
13#include "Trace.h"
14
15using namespace Rappture::VtkVis;
16
17#define MSG_LEN 2047
18
19/**
20 * \brief Open syslog for writing
21 */
22void
23Rappture::VtkVis::initLog()
24{
25    openlog("vtkvis", LOG_CONS | LOG_PERROR | LOG_PID,  LOG_USER);
26}
27
28/**
29 * \brief Close syslog
30 */
31void
32Rappture::VtkVis::closeLog()
33{
34    closelog();
35}
36
37/**
38 * \brief Write a message to syslog
39 */
40void
41Rappture::VtkVis::logMessage(int priority, const char *funcname,
42                             const char *path, int lineNum, const char* fmt, ...)
43{
44    char message[MSG_LEN + 1];
45    const char *s;
46    int length;
47    va_list lst;
48
49    va_start(lst, fmt);
50    s = strrchr(path, '/');
51    if (s == NULL) {
52        s = path;
53    } else {
54        s++;
55    }
56    if (priority & LOG_DEBUG) {
57        length = snprintf(message, MSG_LEN, "%s:%d(%s): ", s, lineNum, funcname);
58    } else {
59        length = snprintf(message, MSG_LEN, "%s:%d: ", s, lineNum);
60    }
61    length += vsnprintf(message + length, MSG_LEN - length, fmt, lst);
62    message[MSG_LEN] = '\0';
63
64    syslog(priority, message, length);
65}
Note: See TracBrowser for help on using the repository browser.