1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 *
4 * Copyright 1998-2021 The OpenLDAP Foundation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
10 *
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
14 */
15
16 #include "portable.h"
17
18 #include <stdio.h>
19
20 #include <ac/ctype.h>
21 #include <ac/stdarg.h>
22 #include <ac/string.h>
23 #include <ac/time.h>
24
25 #include "ldap-int.h"
26
27 /*
28 * ldap log
29 */
30
ldap_log_check(LDAP * ld,int loglvl)31 static int ldap_log_check( LDAP *ld, int loglvl )
32 {
33 int errlvl;
34
35 if(ld == NULL) {
36 errlvl = ldap_debug;
37 } else {
38 errlvl = ld->ld_debug;
39 }
40
41 return errlvl & loglvl ? 1 : 0;
42 }
43
ldap_log_printf(LDAP * ld,int loglvl,const char * fmt,...)44 int ldap_log_printf( LDAP *ld, int loglvl, const char *fmt, ... )
45 {
46 char buf[ 1024 ];
47 va_list ap;
48
49 if ( !ldap_log_check( ld, loglvl )) {
50 return 0;
51 }
52
53 va_start( ap, fmt );
54
55 buf[sizeof(buf) - 1] = '\0';
56 vsnprintf( buf, sizeof(buf)-1, fmt, ap );
57
58 va_end(ap);
59
60 (*ber_pvt_log_print)( buf );
61 return 1;
62 }
63