Added additional UFAFs, fixed gsprintconsole_ves to handle float measruement intervals
[com/gs-lite.git] / include / gslog.h
1  /*------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3    Licensed under the Apache License, Version 2.0 (the "License");
4    you may not use this file except in compliance with the License.
5    You may obtain a copy of the License at
6
7      http://www.apache.org/licenses/LICENSE-2.0
8
9    Unless required by applicable law or agreed to in writing, software
10    distributed under the License is distributed on an "AS IS" BASIS,
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    See the License for the specific language governing permissions and
13    limitations under the License.
14  ------------------------------------------- */
15
16 /*
17  * gslog.h: syslog wrappers for GS-lite
18  */
19 #ifndef GSLOG_H
20 #define GSLOG_H
21
22
23 #include "unistd.h"
24 #include "sys/syslog.h"
25 #include "stdio.h"
26 #include "stdlib.h"
27 #include "string.h"
28 #include "stdarg.h"
29 #include "time.h"
30 #include "gsconfig.h"
31 #include "gstypes.h"
32
33 #ifdef LOGSTDERR
34 static inline void gslog(int loglevel, const char * format, ...) {
35     va_list args;
36     va_start(args, format);
37     if (loglevel >= LOG_WARNING) {
38         vfprintf(stdout, format, args);
39         // Not generally syslog messages do not contain a \n so we need to add one for stdout/stderr
40         fprintf(stdout, "\n");
41         fflush(stdout);
42     } else {
43         //STDERR is not-buffered by default.
44         vfprintf(stderr, format, args);
45         fprintf(stderr, "\n");
46     }
47     va_end(args);
48 }
49
50 static inline void gsopenlog(gs_sp_t p) {
51     return;
52 }
53
54 #else
55
56 #define gslog syslog
57
58 #ifndef LOG_EMERG
59 #define LOG_EMERG 7
60 #endif
61
62 // some state used for reporting
63
64 extern gs_uint64_t intupledrop;
65 extern gs_uint64_t outtupledrop;
66 extern gs_uint64_t intuple;
67 extern gs_uint64_t outtuple;
68 extern gs_uint64_t inbytes;
69 extern gs_uint64_t outbytes;
70 extern gs_uint64_t cycles;
71
72
73 static inline void gsopenlog(gs_sp_t p) {
74         gs_int8_t c[HOST_NAME_MAX+1];
75         gs_int8_t t[HOST_NAME_MAX+1+1000];
76         gs_sp_t t2;
77         if (gethostname(&c[0],HOST_NAME_MAX+1)!=0) {
78                 fprintf(stderr,"GSCPV1::ERROR:could not get hostname\n");
79                 exit(1);
80         }
81         c[HOST_NAME_MAX]=0;
82         sprintf(t,"GSCPv2:%s:%s:",c,p);
83         t2=strdup(t);
84         openlog(t2,LOG_NOWAIT|LOG_PID|LOG_CONS,LOG_LOCAL5);
85         gslog(LOG_INFO,"Started Logging");
86         intupledrop=0;
87         outtupledrop=0;
88         intuple=0;
89         outtuple=0;
90         inbytes=0;
91         outbytes=0;
92         cycles=0;
93 }
94 #endif
95
96 static inline void gsstats() {
97         gs_uint32_t t;
98         //t=time(0);
99         //gslog(LOG_NOTICE,"STATS|%u|%llu|%llu|%llu|%llu|%llu|%llu|%llu",t,intuple,inbytes,intupledrop,outtuple,outbytes,outtupledrop,cycles);
100 }
101
102 #endif