Mon, 23 Jan 2023 22:02:35 +0100
demon.php: Add API debug output, lower speel delay
0
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
1 | <?php |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
2 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
3 | ## simple debug framework |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
4 | ## (grin) |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
5 | ## |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
6 | ## $Id$ |
2 | 7 | ## |
0
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
8 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
9 | class Debug { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
10 | private $debuglevel = 2; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
11 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
12 | function __construct() { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
13 | // wtf |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
14 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
15 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
16 | function set_level($l) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
17 | $this->debuglevel = $l; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
18 | $this->warn( "Set debug level to $this->debuglevel" ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
19 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
20 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
21 | function msg ($s) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
22 | $this->log( 0, $s ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
23 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
24 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
25 | function error ($s) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
26 | $this->log( 1, $s ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
27 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
28 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
29 | function warn ($s) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
30 | $this->log( 2, $s ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
31 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
32 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
33 | function info ($s) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
34 | $this->log( 5, $s ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
35 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
36 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
37 | function debug ($s) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
38 | $this->log( 8, $s ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
39 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
40 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
41 | function trace ($s) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
42 | $this->log( 9, $s ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
43 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
44 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
45 | function log ($level,$msg) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
46 | #$now = strftime("%Y-%m-%d %T"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
47 | if( $level > $this->debuglevel ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
48 | return; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
49 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
50 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
51 | $now = date('c'); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
52 | print( "$now [$level] $msg\n" ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
53 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
54 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
55 |