support_log.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /*
10  * -----------------------------------------------------------------------------
11  *
12  * Author: Markus Moeller (markus_moeller at compuserve.com)
13  *
14  * Copyright (C) 2007 Markus Moeller. All rights reserved.
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
29  *
30  * -----------------------------------------------------------------------------
31  */
32 
33 #include "squid.h"
34 
35 #if HAVE_LDAP
36 
37 #include "support.h"
38 #include <ctime>
39 
40 const char *
41 LogTime()
42 {
43  static time_t last_t = 0;
44  struct timeval now;
45  static char buf[128];
46 
47  gettimeofday(&now, nullptr);
48  if (now.tv_sec != last_t) {
49  struct tm *tm;
50  time_t tmp = now.tv_sec;
51  tm = localtime(&tmp);
52  strftime(buf, 127, "%Y/%m/%d %H:%M:%S", tm);
53  last_t = now.tv_sec;
54  }
55  return buf;
56 }
57 /* default off */
58 int log_enabled = 0;
59 
60 #ifndef __GNUC__
61 /* under gcc a macro define in compat/debug.h is used instead */
62 
63 void
64 log(char *format,...)
65 {
66  if (!log_enabled)
67  return;
68  va_list args;
69  va_start(args, format);
70  vfprintf(stderr, format, args);
71  va_end(args);
72 }
73 
74 void
75 error(char *format,...)
76 {
77  va_list args;
78  va_start(args, format);
79  vfprintf(stderr, format, args);
80  va_end(args);
81 }
82 
83 void
84 warn(char *format,...)
85 {
86  va_list args;
87  va_start(args, format);
88  vfprintf(stderr, format, args);
89  va_end(args);
90 }
91 
92 #endif /* __GNUC__ */
93 #endif
94 
void log(char *format,...)
void error(char *format,...)
void warn(char *format,...)
const char * LogTime(void)
int log_enabled

 

Introduction

Documentation

Support

Miscellaneous