source: trunk/packages/vizservers/geovis/Trace.cpp @ 4369

Last change on this file since 4369 was 3998, checked in by ldelgass, 11 years ago

Add prelimilary skeleton for geovis map rendering server. Not functional, not
integrated into configure, etc.

File size: 1.8 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (C) 2004-2013  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 <string>
14#include <sstream>
15
16#include "Trace.h"
17
18using namespace GeoVis;
19
20static std::ostringstream g_UserErrorString;
21
22#define MSG_LEN 2047
23
24/**
25 * \brief Open syslog for writing
26 */
27void
28GeoVis::initLog()
29{
30    openlog("geovis", LOG_CONS | LOG_PERROR | LOG_PID,  LOG_USER);
31}
32
33/**
34 * \brief Close syslog
35 */
36void
37GeoVis::closeLog()
38{
39    closelog();
40}
41
42/**
43 * \brief Write a message to syslog
44 */
45void
46GeoVis::logMessage(int priority, const char *funcname,
47                   const char *path, int lineNum, const char* fmt, ...)
48{
49    char message[MSG_LEN + 1];
50    const char *s;
51    int length;
52    va_list lst;
53
54    va_start(lst, fmt);
55    s = strrchr(path, '/');
56    if (s == NULL) {
57        s = path;
58    } else {
59        s++;
60    }
61    if (priority & LOG_DEBUG) {
62        length = snprintf(message, MSG_LEN, "%s:%d(%s): ", s, lineNum, funcname);
63    } else {
64        length = snprintf(message, MSG_LEN, "%s:%d: ", s, lineNum);
65    }
66    length += vsnprintf(message + length, MSG_LEN - length, fmt, lst);
67    message[MSG_LEN] = '\0';
68
69    syslog(priority, "%s", message);
70}
71
72/**
73 * \brief Write a user message to buffer
74 */
75void
76GeoVis::logUserMessage(const char* fmt, ...)
77{
78    char message[MSG_LEN + 1];
79    int length = 0;
80    va_list lst;
81
82    va_start(lst, fmt);
83
84    length += vsnprintf(message, MSG_LEN, fmt, lst);
85    message[MSG_LEN] = '\0';
86
87    g_UserErrorString << message << "\n";
88}
89
90const char *
91GeoVis::getUserMessages()
92{
93    return g_UserErrorString.str().c_str();
94}
95
96void
97GeoVis::clearUserMessages()
98{
99    g_UserErrorString.str(std::string());
100}
Note: See TracBrowser for help on using the repository browser.