1 : <?php
2 : /**
3 : * LICENSE
4 : *
5 : * "THE BEER-WARE LICENSE" (Revision 42):
6 : * "Sven Strittmatter" <ich@weltraumschaf.de> wrote this file.
7 : * As long as you retain this notice you can do whatever you want with
8 : * this stuff. If we meet some day, and you think this stuff is worth it,
9 : * you can buy me a beer in return.
10 : *
11 : * @author Sven Strittmatter <ich@weltraumschaf.de>
12 : * @copyright Copyright (c) 2010, Sven Strittmatter.
13 : * @version 0.2.2
14 : * @license http://www.weltraumschaf.de/the-beer-ware-license.txt
15 : */
16 :
17 : /**
18 : * Simple logger class.
19 : *
20 : * Collects all log messages in an array. Has no persistence.
21 : */
22 : class Api_Log {
23 : /**
24 : * Flags if logging is enabled.
25 : *
26 : * @var bool
27 : */
28 : private static $isEnabled = true;
29 : /**
30 : * Stores the log messages.
31 : *
32 : * @var array
33 : */
34 : private static $logLines = array();
35 :
36 : /**
37 : * Stores a log message.
38 : *
39 : * @param string $message
40 : */
41 : public static function log($message) {
42 8 : if (self::$isEnabled) {
43 6 : self::$logLines[] = (string) $message;
44 6 : }
45 8 : }
46 :
47 : /**
48 : * Get all log messages.
49 : *
50 : * @return array
51 : */
52 : public static function get() {
53 2 : return self::$logLines;
54 : }
55 :
56 : /**
57 : * Enables logging.
58 : *
59 : * Logging is enabled by default, unless you call Api_Log::disable().
60 : */
61 : public static function enable() {
62 2 : self::$isEnabled = true;
63 2 : }
64 :
65 : /**
66 : * Disables logging.
67 : *
68 : * If you call this method all calls to Api_Log::log() will be ignored
69 : * until you call Api_Log::enable().
70 : */
71 : public static function disable() {
72 2 : self::$isEnabled = false;
73 2 : }
74 :
75 : /**
76 : * Deletes all logmessages.
77 : */
78 : public static function clear() {
79 7 : self::$logLines = array();
80 7 : }
81 : }
|