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
7 http://www.apache.org/licenses/LICENSE-2.0
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 ------------------------------------------- */
17 * gslog.h: syslog wrappers for GS-lite
24 #include "sys/syslog.h"
34 static inline void gslog(int loglevel, const char * format, ...) {
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");
43 //STDERR is not-buffered by default.
44 vfprintf(stderr, format, args);
45 fprintf(stderr, "\n");
50 static inline void gsopenlog(gs_sp_t p) {
62 // some state used for reporting
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;
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];
77 if (gethostname(&c[0],HOST_NAME_MAX+1)!=0) {
78 fprintf(stderr,"GSCPV1::ERROR:could not get hostname\n");
82 sprintf(t,"GSCPv2:%s:%s:",c,p);
84 openlog(t2,LOG_NOWAIT|LOG_PID|LOG_CONS,LOG_LOCAL5);
85 gslog(LOG_INFO,"Started Logging");
96 static inline void gsstats() {
99 //gslog(LOG_NOTICE,"STATS|%u|%llu|%llu|%llu|%llu|%llu|%llu|%llu",t,intuple,inbytes,intupledrop,outtuple,outbytes,outtupledrop,cycles);