File: syslog.php

package info (click to toggle)
phpldapadmin 1.1.0.5-6%2Blenny2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,008 kB
  • ctags: 3,949
  • sloc: php: 17,735; xml: 1,532; sh: 388; makefile: 46
file content (104 lines) | stat: -rw-r--r-- 3,183 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/syslog.php,v 1.13.2.1 2007/12/26 09:26:33 wurley Exp $

/**
 * Functions related to syslog logging.
 *
 * @author Benjamin Drieu <benjamin.drieu@fr.alcove.com> and AlcĂ´ve
 * @package phpLDAPadmin
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

# If config_default.php hasnt been called yet, then return.
if (! defined('APPCONFIG') || ! isset($_SESSION[APPCONFIG]))
	return;

/* Initialize syslog */
if ($_SESSION[APPCONFIG]->GetValue('debug','syslog')) {
	define_syslog_variables();
	openlog('phpldapadmin', LOG_ODELAY, LOG_DAEMON );
}

/**
 * Verify that syslog logging is activated in the config via the
 * debug->syslog variable and does a call to the syslog() function is it
 * is true.
 *
 * @param emergency	Syslog emergency.
 * @param log_string	String to log.
 */
function syslog_msg ( $emergency, $log_string, $ldapserver=null ) {
	if (isset($_SESSION[APPCONFIG]) && $_SESSION[APPCONFIG]->GetValue('debug','syslog')) {

		if (isset($ldapserver->server_id))
			$log_string = sprintf('(%s) %s',$ldapserver->getLoggedInDN(),$log_string);

		syslog ( $emergency, $log_string );
	}

	return true;
}

/**
 * Issue an error message via syslog.
 *
 * @param log_string	Log message to send to syslog.
 * @param server_id	If set, print the logged user as well.
 *
 * @return true on success.
 */
function syslog_err ( $log_string, $ldapserver=null ) {
	return syslog_msg ( LOG_ERR, $log_string, $ldapserver );
}

/**
 * Issue a warning message via syslog.
 *
 * @param log_string	Log message to send to syslog.
 * @param server_id	If set, print the logged user as well.
 *
 * @return true on success.
 */
function syslog_warning ( $log_string, $ldapserver=null ) {
	return syslog_msg ( LOG_WARNING, $log_string, $ldapserver );
}

/**
 * Issue a notice message via syslog.
 *
 * @param log_string	Log message to send to syslog.
 * @param server_id	If set, print the logged user as well.
 *
 * @return true on success.
 */
function syslog_notice ( $log_string, $ldapserver=null ) {
	return syslog_msg ( LOG_NOTICE, $log_string, $ldapserver );
}

/**
 * Issue a debug message via syslog, only if $log_level is set to
 * 'debug' from the config file.
 *
 * @param log_string	Log message to send to syslog.
 * @param server_id	If set, print the logged user as well.
 *
 * @return true on success or if debug log is not activated.
 */
function syslog_debug ( $log_string, $ldapserver=null ) {
	return syslog_msg ( LOG_DEBUG, $log_string, $ldapserver );
}
?>