Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 107 lines (76 sloc) 3.675 kB
618b939 @jbroadway Moved code to lib/ folder, added optional PSR-0 support, added PSR-0 …
authored
1 ## Analog - PHP 5.3+ micro logging package
161bddb @jbroadway Initial import
authored
2
3454276 @jbroadway Updated readme
authored
3 * Copyright: (c) 2012 Johnny Broadway
4 * License: http://www.opensource.org/licenses/mit-license.php
161bddb @jbroadway Initial import
authored
5
736a44a @jbroadway Updated readme
authored
6 <a href='http://www.pledgie.com/campaigns/16595'><img alt='Click here to lend your support to: Analog and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/16595.png?skin_name=chrome' border='0' /></a>
7
618b939 @jbroadway Moved code to lib/ folder, added optional PSR-0 support, added PSR-0 …
authored
8 A [MicroPHP](http://microphp.org/) logging package based on the idea of using closures
9 for configurability and extensibility. It functions as a static class, but you can
0db8611 @jbroadway Removed format closure, renamed location to handler
authored
10 completely control the writing of log messages through a closure function
915812d @jbroadway Updated readme
authored
11 (aka [anonymous functions](http://ca3.php.net/manual/en/functions.anonymous.php)).
161bddb @jbroadway Initial import
authored
12
0db8611 @jbroadway Removed format closure, renamed location to handler
authored
13 By default, this class will write to a file named `sys_get_temp_dir() . '/analog.txt'`
14 using the format `"machine - date - level - message\n"`, making it usable with no
15 customization necessary.
161bddb @jbroadway Initial import
authored
16
b2f5143 @jbroadway Added handler to write to Amon server monitoring tool
authored
17 Analog also comes with over a dozen pre-written handlers in the Analog/Handlers folder,
c550c40 @jbroadway Updated readme
authored
18 with examples for each in the examples folder. These include:
9c72ed9 @jbroadway Updated readme
authored
19
b2f5143 @jbroadway Added handler to write to Amon server monitoring tool
authored
20 * Amon - Send logs to the [Amon](http://amon.cx/) server monitoring tool
139117c @jbroadway Updated readme
authored
21 * Buffer - Buffer messages to send all at once (works with File, Mail, Stderr, and Variable handlers)
9c72ed9 @jbroadway Updated readme
authored
22 * File - Append messages to a file
23 * FirePHP - Send messages to [FirePHP](http://www.firephp.org/) browser plugin
8b67e51 @jbroadway Added support for Graylog2
authored
24 * GELF - Send message to the [Graylog2](http://www.graylog2.org/) log management server
2279944 @jbroadway Updated readme
authored
25 * LevelBuffer - Buffer messages and send only if sufficient error level reached
9c72ed9 @jbroadway Updated readme
authored
26 * Mail - Send email notices
27 * Mongo - Save to MongoDB collection
28 * Multi - Send different log levels to different handlers
29 * Null - Do nothing
30 * Post - Send messages over HTTP POST to another machine
31 * Stderr - Send messages to STDERR
32 * Syslog - Send messages to syslog
33 * Variable - Buffer messages to a variable reference.
7dc2e34 @jbroadway Updated readme
authored
34
618b939 @jbroadway Moved code to lib/ folder, added optional PSR-0 support, added PSR-0 …
authored
35 So while it's a micro class, it's highly extensible and very capable out of the box too.
c550c40 @jbroadway Updated readme
authored
36
7dc2e34 @jbroadway Updated readme
authored
37 ### Rationale
38
6ccba09 @jbroadway Updated readme
authored
39 I wrote this because I wanted something very small and simple like
3454276 @jbroadway Updated readme
authored
40 [KLogger](https://github.com/katzgrau/KLogger), and preferably not torn out
41 of a wider framework if possible. After searching, I wasn't happy with the
42 single-purpose libraries I found. With KLogger for example, I didn't want an
43 object instance but rather a static class, and I wanted more flexibility in
44 the back-end.
161bddb @jbroadway Initial import
authored
45
6ccba09 @jbroadway Updated readme
authored
46 I also found some that had the flexibility also had more complexity, for example
47 [Monolog](https://github.com/Seldaek/monolog) is 25 source files (not incl. tests).
9c72ed9 @jbroadway Updated readme
authored
48 With closures, this seemed to be a good balance of small without sacrificing
49 flexibility.
161bddb @jbroadway Initial import
authored
50
6ccba09 @jbroadway Updated readme
authored
51 > What about Analog, the logfile analyzer? Well, since it hasn't been updated
52 > since 2004, I think it's safe to call a single-file PHP logging class the
53 > same thing without it being considered stepping on toes :)
161bddb @jbroadway Initial import
authored
54
7dc2e34 @jbroadway Updated readme
authored
55 ### Usage
161bddb @jbroadway Initial import
authored
56
618b939 @jbroadway Moved code to lib/ folder, added optional PSR-0 support, added PSR-0 …
authored
57 Standard usage:
58
161bddb @jbroadway Initial import
authored
59 ```php
60 <?php
61
62 require_once ('Analog.php');
63
0db8611 @jbroadway Removed format closure, renamed location to handler
authored
64 // Default logging to /tmp/analog.txt
65 Analog::log ('Log this error');
161bddb @jbroadway Initial import
authored
66
67 // Log to a MongoDB log collection
0db8611 @jbroadway Removed format closure, renamed location to handler
authored
68 Analog::handler (function ($info) {
161bddb @jbroadway Initial import
authored
69 static $conn = null;
70 if (! $conn) {
71 $conn = new Mongo ('localhost:27017');
72 }
0db8611 @jbroadway Removed format closure, renamed location to handler
authored
73 $conn->mydb->log->insert ($info);
161bddb @jbroadway Initial import
authored
74 });
75
0db8611 @jbroadway Removed format closure, renamed location to handler
authored
76 // Log an alert
77 Analog::log ('The sky is falling!', Analog::ALERT);
161bddb @jbroadway Initial import
authored
78
79 // Log some debug info
80 Analog::log ('Debugging info', Analog::DEBUG);
81
82 ?>
83 ```
9c72ed9 @jbroadway Updated readme
authored
84
618b939 @jbroadway Moved code to lib/ folder, added optional PSR-0 support, added PSR-0 …
authored
85 PSR-0 usage:
86
87 ```php
88 <?php
89
90 require_once ('SplClassLoader.php');
91
92 $loader = new SplClassLoader ('Analog', 'lib');
93 $loader->register ();
94
95 use \Analog\Analog;
96
97 Analog::log ('Log this error');
98
99 Analog::handler (\Analog\Handler\FirePHP::init ());
100
101 Analog::log ('Take me to your browser');
102
103 ?>
104 ```
105
9c72ed9 @jbroadway Updated readme
authored
106 For more examples, see the [examples](https://github.com/jbroadway/analog/tree/master/examples) folder.
Something went wrong with that request. Please try again.