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 | |
---|
15 | using namespace Rappture::VtkVis; |
---|
16 | |
---|
17 | #define MSG_LEN 2047 |
---|
18 | |
---|
19 | /** |
---|
20 | * \brief Open syslog for writing |
---|
21 | */ |
---|
22 | void |
---|
23 | Rappture::VtkVis::initLog() |
---|
24 | { |
---|
25 | openlog("vtkvis", LOG_CONS | LOG_PERROR | LOG_PID, LOG_USER); |
---|
26 | } |
---|
27 | |
---|
28 | /** |
---|
29 | * \brief Close syslog |
---|
30 | */ |
---|
31 | void |
---|
32 | Rappture::VtkVis::closeLog() |
---|
33 | { |
---|
34 | closelog(); |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * \brief Write a message to syslog |
---|
39 | */ |
---|
40 | void |
---|
41 | Rappture::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 | } |
---|