summaryrefslogtreecommitdiff
path: root/framework/Log/EventLog/writers/writer_unix_file.php
diff options
context:
space:
mode:
authorwei <>2006-01-04 08:10:56 +0000
committerwei <>2006-01-04 08:10:56 +0000
commit3628bfe141ef02299beb9514397cfc2c27a7dcb1 (patch)
treee1b09079bee418e45af6c49314a9f0fec5cf2012 /framework/Log/EventLog/writers/writer_unix_file.php
parent0ebae0856a5ed24bcc1b01d13d8715288f39a08d (diff)
adding TEventLog using ezcLog from ezComponents.
Diffstat (limited to 'framework/Log/EventLog/writers/writer_unix_file.php')
-rw-r--r--framework/Log/EventLog/writers/writer_unix_file.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/framework/Log/EventLog/writers/writer_unix_file.php b/framework/Log/EventLog/writers/writer_unix_file.php
new file mode 100644
index 00000000..a2045217
--- /dev/null
+++ b/framework/Log/EventLog/writers/writer_unix_file.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * File containing the ezcLogWriterUnix class.
+ *
+ * @package EventLog
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Writes the log messages to a file in a format that is frequently used on the Unix operating system.
+ *
+ * @package EventLog
+ * @version //autogentag//
+ */
+class ezcLogWriterUnixFile extends ezcLogWriterFile
+{
+ /**
+ * Write the logEntries to a file.
+ *
+ * Each line in the log file represents a log message. The log
+ * messages have the following style:
+ * <pre>
+ * MMM dd HH:mm:ss [Severity] [Source] [Category] Message (ExtraInfo)
+ * </pre>
+ *
+ * With:
+ * - MMM: The 3 letter abbreviation of the month.
+ * - dd: The day of the month.
+ * - HH: The hour.
+ * - mm: The minutes.
+ * - ss: The seconds.
+ *
+ * Example:
+ * <pre>
+ * Jan 24 15:32:56 [Debug] [Paynet] [Shop] Connecting to the paynet server (file: paynet_server.php, line: 224).
+ * Jan 24 15:33:01 [Debug] [Paynet] [Shop] Connected with the server (file: paynet_server.php, line: 710).
+ * </pre>
+ *
+ * This method will be called by the {@link ezcLog} class. The $eventSource and $eventCategory are either given
+ * in the {@link ezcLog::log()} method or are the defaults from the {@link ezcLog} class.
+ *
+ * @param string $message
+ * @param int $eventType
+ * @param string $eventType
+ * @param string $eventCategory
+ * @param array(string=>string) $extraInfo
+ */
+ public function writeLogMessage( $message, $eventType, $eventSource, $eventCategory, $extraInfo = array() )
+ {
+ $extra = $this->implodeWithKey( ", ", ": ", $extraInfo );
+
+ if ( $eventCategory == false )
+ {
+ $eventCategory = "";
+ }
+ $logMsg = @date( "M d H:i:s" ) .
+ " [".ezcLog::translateSeverityName( $eventType ) .
+ "] [$eventSource] [$eventCategory] $message ($extra)\n";
+
+ $this->write( $eventType, $eventSource, $eventCategory, $logMsg );
+ }
+
+ /**
+ * Returns a string from the hash $data.
+ *
+ * The string $splitEntry specifies the string that will be inserted between the pairs.
+ * The string $splitKeyVal specifies the string that will be inserted in each pair.
+ *
+ * Example:
+ * <code>
+ * $this->implodeWithKey( ", ", ": ", array( "Car" => "red", "Curtains" => "blue" );
+ * </code>
+ *
+ * Will create the following string:
+ * <pre>
+ * Car: red, Curtains: blue
+ * </pre>
+ *
+ * @param string $splitEntry
+ * @param string $splitKeyVal
+ * @param array(mixed=>mixed) $data
+ * @return string
+ */
+ protected function implodeWithKey( $splitEntry, $splitKeyVal, $data)
+ {
+ $total = "";
+ if ( is_array( $data ) )
+ {
+ foreach ( $data as $key => $val )
+ {
+ $total .= $splitEntry . $key . $splitKeyVal . $val;
+ }
+ }
+
+ return substr( $total, strlen( $splitEntry ) );
+ }
+}
+?>