2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2002-2015 The OpenLDAP Foundation.
5 * Portions Copyright 1997,2002-2003 IBM Corporation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by IBM Corporation for use in
18 * IBM products and subsequently ported to OpenLDAP Software by
24 #include <ac/string.h>
25 #include <ac/stdarg.h>
26 #include <ac/unistd.h>
31 #include <ldap_config.h>
35 #include <ldap_pvt_thread.h>
37 /* Single threads access to routine */
38 ldap_pvt_thread_mutex_t slapi_printmessage_mutex;
39 char *slapi_log_file = NULL;
40 int slapi_log_level = SLAPI_LOG_PLUGIN;
56 assert( subsystem != NULL );
57 assert( fmt != NULL );
59 ldap_pvt_thread_mutex_lock( &slapi_printmessage_mutex ) ;
61 /* for now, we log all severities */
62 if ( level <= slapi_log_level ) {
63 fp = fopen( slapi_log_file, "a" );
72 while ( lockf( fileno( fp ), F_LOCK, 0 ) != 0 ) {
77 ltm = localtime( ¤tTime );
78 strftime( timeStr, sizeof(timeStr), "%x %X", ltm );
81 fprintf( fp, " %s: ", subsystem );
82 vfprintf( fp, fmt, arglist );
83 if ( fmt[ strlen( fmt ) - 1 ] != '\n' ) {
88 lockf( fileno( fp ), F_ULOCK, 0 );
97 ldap_pvt_thread_mutex_unlock( &slapi_printmessage_mutex );