protected function appendToFile($logfile, $logstring, $explicit = false) {

		$class = \hlin\PHP::unn(__CLASS__);

		# logging signatures are intended to prevent duplication PER REQUEST
		# on a per logger instance basis, not cull duplicate messages per log

		$sig = crc32($logstring);
		$filesig = crc32($sig.$logfile);

		// have we already logged the message?
		if ( ! in_array($filesig, $this->filesigs)) {

			$fs = $this->fs;
			$filepath = $this->logspath.'/'.$logfile.'.log';
			$dir = $fs->dirname($filepath);

			if ( ! $fs->file_exists($dir)) {
				if ( ! $fs->mkdir($dir, $this->dirPermission(), true)) {
					$this->failedLogging(null, "[$class] Failed to create directories: $dir");
					return;
				}
			}

			// does the file exist?
			if ( ! $fs->file_exists($filepath)) {
				// ensure the file exists
				if ( ! $fs->touch($filepath)) {
					$this->failedLogging(null, "[$class] Failed to create log file: $filepath");
					return;
				}
				// ensure the permissions are right
				if ( ! $fs->chmod($filepath, $this->filePermission())) {
					$this->failedLogging(null, "[$class] Failed to set permissions on log file: $filepath");
					return;
				}
			}

			if ( ! $fs->file_append_contents($filepath, "$logstring\n")) {
				$this->failedLogging(null, "[$class] Failed to append to log: $filepath");
			}

			// intentionally recording signature only after success
			$this->filesigs[] = $filesig;

			// have we stored the summary report?
			if ( ! $explicit && ! in_array($sig, $this->sigs)) {

				$filepath = $this->logspath.'/summary.log';

				# we don't need to ensure directory structure; it's already
				# been ensured by previous operations of recording the long
				# term complete log message

				// we only record the first line in the summary log
				if (($ptr = stripos($logstring, "\n")) !== false) {
					$summary = trim(substr($logstring, 0, $ptr));
				}
				else { // no end of line detected
					$summary = trim($logstring);
				}

				if ( ! $fs->file_append_contents($filepath, "$summary\n")) {
					$this->failedLogging(null, "[$class] Failed to append to log: $filepath");
				}

				// intentionally recording signature only after success
				$this->sigs[] = $sig;
			}
		}
	}
protected function appendToFile($logfile, $logstring, $explicit = false) {

		$class = \hlin\PHP::unn(__CLASS__);

		# logging signatures are intended to prevent duplication PER REQUEST
		# on a per logger instance basis, not cull duplicate messages per log

		$sig = crc32($logstring);
		$filesig = crc32($sig.$logfile);

		// have we already logged the message?
		if ( ! in_array($filesig, $this->filesigs)) {

			$fs = $this->fs;
			$filepath = $this->logspath.'/'.$logfile.'.log';
			$dir = $fs->dirname($filepath);

			if ( ! $fs->file_exists($dir)) {
				if ( ! $fs->mkdir($dir, $this->dirPermission(), true)) {
					$this->failedLogging(null, "[$class] Failed to create directories: $dir");
					return;
				}
			}

			// does the file exist?
			if ( ! $fs->file_exists($filepath)) {
				// ensure the file exists
				if ( ! $fs->touch($filepath)) {
					$this->failedLogging(null, "[$class] Failed to create log file: $filepath");
					return;
				}
				// ensure the permissions are right
				if ( ! $fs->chmod($filepath, $this->filePermission())) {
					$this->failedLogging(null, "[$class] Failed to set permissions on log file: $filepath");
					return;
				}
			}

			if ( ! $fs->file_append_contents($filepath, "$logstring\n")) {
				$this->failedLogging(null, "[$class] Failed to append to log: $filepath");
			}

			// intentionally recording signature only after success
			$this->filesigs[] = $filesig;

			// have we stored the summary report?
			if ( ! $explicit && ! in_array($sig, $this->sigs)) {

				$filepath = $this->logspath.'/summary.log';

				# we don't need to ensure directory structure; it's already
				# been ensured by previous operations of recording the long
				# term complete log message

				// we only record the first line in the summary log
				if (($ptr = stripos($logstring, "\n")) !== false) {
					$summary = trim(substr($logstring, 0, $ptr));
				}
				else { // no end of line detected
					$summary = trim($logstring);
				}

				if ( ! $fs->file_append_contents($filepath, "$summary\n")) {
					$this->failedLogging(null, "[$class] Failed to append to log: $filepath");
				}

				// intentionally recording signature only after success
				$this->sigs[] = $sig;
			}
		}
	}
protected function appendToFile ( $ logfile , $ logstring , $ explicit = false ) { $ class = \ hlin \ PHP :: unn ( __CLASS__ ) ; # logging signatures are intended to prevent duplication PER REQUEST # on a per logger instance basis, not cull duplicate messages per log $ sig = crc32 ( $ logstring ) ; $ filesig = crc32 ( $ sig . $ logfile ) ; // have we already logged the message? if ( ! in_array ( $ filesig , $ this -> filesigs ) ) { $ fs = $ this -> fs ; $ filepath = $ this -> logspath . '/' . $ logfile . '.log' ; $ dir = $ fs -> dirname ( $ filepath ) ; if ( ! $ fs -> file_exists ( $ dir ) ) { if ( ! $ fs -> mkdir ( $ dir , $ this -> dirPermission ( ) , true ) ) { $ this -> failedLogging ( null , "[$class] Failed to create directories: $dir" ) ; return ; } } // does the file exist? if ( ! $ fs -> file_exists ( $ filepath ) ) { // ensure the file exists if ( ! $ fs -> touch ( $ filepath ) ) { $ this -> failedLogging ( null , "[$class] Failed to create log file: $filepath" ) ; return ; } // ensure the permissions are right if ( ! $ fs -> chmod ( $ filepath , $ this -> filePermission ( ) ) ) { $ this -> failedLogging ( null , "[$class] Failed to set permissions on log file: $filepath" ) ; return ; } } if ( ! $ fs -> file_append_contents ( $ filepath , "$logstring\n" ) ) { $ this -> failedLogging ( null , "[$class] Failed to append to log: $filepath" ) ; } // intentionally recording signature only after success $ this -> filesigs [ ] = $ filesig ; // have we stored the summary report? if ( ! $ explicit && ! in_array ( $ sig , $ this -> sigs ) ) { $ filepath = $ this -> logspath . '/summary.log' ; # we don't need to ensure directory structure; it's already # been ensured by previous operations of recording the long # term complete log message // we only record the first line in the summary log if ( ( $ ptr = stripos ( $ logstring , "\n" ) ) !== false ) { $ summary = trim ( substr ( $ logstring , 0 , $ ptr ) ) ; } else { // no end of line detected $ summary = trim ( $ logstring ) ; } if ( ! $ fs -> file_append_contents ( $ filepath , "$summary\n" ) ) { $ this -> failedLogging ( null , "[$class] Failed to append to log: $filepath" ) ; } // intentionally recording signature only after success $ this -> sigs [ ] = $ sig ; } } }
Appeds to the logfile. The logfile is relative to the logs directory.
If the logfile doesn't exist yet the system will create it. The '.log'
extention is automatically appended, along with a single
newline character.
Appeds to the logfile . The logfile is relative to the logs directory . If the logfile doesn t exist yet the system will create it . The . log extention is automatically appended along with a single newline character .