101 $this->_id = md5(microtime());
102 $this->_filename =
$name;
103 $this->_ident = $ident;
106 if (isset($conf[
'append'])) {
107 $this->_append = $conf[
'append'];
110 if (isset($conf[
'locking'])) {
111 $this->_locking = $conf[
'locking'];
114 if (!empty($conf[
'mode'])) {
115 if (is_string($conf[
'mode'])) {
116 $this->_mode = octdec($conf[
'mode']);
118 $this->_mode = $conf[
'mode'];
122 if (!empty($conf[
'dirmode'])) {
123 if (is_string($conf[
'dirmode'])) {
124 $this->_dirmode = octdec($conf[
'dirmode']);
126 $this->_dirmode = $conf[
'dirmode'];
130 if (!empty($conf[
'lineFormat'])) {
131 $this->_lineFormat = str_replace(array_keys($this->_formatMap),
132 array_values($this->_formatMap),
133 $conf[
'lineFormat']);
136 if (!empty($conf[
'timeFormat'])) {
137 $this->_timeFormat = $conf[
'timeFormat'];
140 if (!empty($conf[
'eol'])) {
141 $this->_eol = $conf[
'eol'];
143 $this->_eol = (strstr(PHP_OS,
'WIN')) ?
"\r\n" :
"\n";
146 register_shutdown_function(array(&$this,
'_Log_file'));
154 if ($this->_opened) {
177 $head = dirname($path);
178 $tail = basename($path);
182 $head = dirname($path);
183 $tail = basename($path);
187 if (!empty($head) && !empty($tail) && !is_dir($head)) {
192 return @mkdir($head, $mode);
206 if (!$this->_opened) {
208 if (!is_dir(dirname($this->_filename))) {
209 $this->
_mkpath($this->_filename, $this->_dirmode);
213 $creating = !file_exists($this->_filename);
216 $this->_fp = fopen($this->_filename, ($this->_append) ?
'a' :
'w');
219 $this->_opened = ($this->_fp !==
false);
222 if ($creating && $this->_opened) {
223 chmod($this->_filename, $this->_mode);
238 if ($this->_opened && fclose($this->_fp)) {
239 $this->_opened =
false;
242 return ($this->_opened ===
false);
253 if (is_resource($this->_fp)) {
254 return fflush($this->_fp);
272 function log($message, $priority = null)
275 if ($priority === null) {
285 if (!$this->_opened && !$this->
open()) {
293 $line = $this->
_format($this->_lineFormat,
294 strftime($this->_timeFormat),
298 if ($this->_locking) {
299 flock($this->_fp, LOCK_EX);
303 $success = (fwrite($this->_fp, $line) !==
false);
306 if ($this->_locking) {
307 flock($this->_fp, LOCK_UN);
311 $this->
_announce(array(
'priority' => $priority,
'message' => $message));