source: extensions/oAuth/include/test/hybridauth/Hybrid/Logger.php @ 20293

Last change on this file since 20293 was 20293, checked in by mistic100, 11 years ago

first commit of oAuth plugin, still in developpement

File size: 2.0 KB
Line 
1<?php
2/*!
3* HybridAuth
4* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6*/
7 
8/**
9 * Debugging and Logging manager
10 */
11class Hybrid_Logger
12{
13        function __construct()
14        {
15                // if debug mode is set to true, then check for the writable log file
16                if ( Hybrid_Auth::$config["debug_mode"] ){
17                        if ( ! file_exists( Hybrid_Auth::$config["debug_file"] ) ){
18                                throw new Exception( "'debug_mode' is set to 'true', but the file " . Hybrid_Auth::$config['debug_file'] . " in 'debug_file' does not exit.", 1 );
19                        }
20
21                        if ( ! is_writable( Hybrid_Auth::$config["debug_file"] ) ){
22                                throw new Exception( "'debug_mode' is set to 'true', but the given log file path 'debug_file' is not a writable file.", 1 );
23                        }
24                } 
25        }
26
27        public static function debug( $message, $object = NULL )
28        {
29                if( Hybrid_Auth::$config["debug_mode"] ){
30                        $datetime = new DateTime();
31                        $datetime =  $datetime->format(DATE_ATOM);
32
33                        file_put_contents( 
34                                Hybrid_Auth::$config["debug_file"], 
35                                "DEBUG -- " . $_SERVER['REMOTE_ADDR'] . " -- " . $datetime . " -- " . $message . " -- " . print_r($object, true) . "\n", 
36                                FILE_APPEND
37                        );
38                }
39        }
40
41        public static function info( $message )
42        { 
43                if( Hybrid_Auth::$config["debug_mode"] ){
44                        $datetime = new DateTime();
45                        $datetime =  $datetime->format(DATE_ATOM);
46
47                        file_put_contents( 
48                                Hybrid_Auth::$config["debug_file"], 
49                                "INFO -- " . $_SERVER['REMOTE_ADDR'] . " -- " . $datetime . " -- " . $message . "\n", 
50                                FILE_APPEND
51                        );
52                }
53        }
54
55        public static function error($message, $object = NULL)
56        { 
57                if( Hybrid_Auth::$config["debug_mode"] ){
58                        $datetime = new DateTime();
59                        $datetime =  $datetime->format(DATE_ATOM);
60
61                        file_put_contents( 
62                                Hybrid_Auth::$config["debug_file"], 
63                                "ERROR -- " . $_SERVER['REMOTE_ADDR'] . " -- " . $datetime . " -- " . $message . " -- " . print_r($object, true) . "\n", 
64                                FILE_APPEND
65                        );
66                }
67        }
68}
Note: See TracBrowser for help on using the repository browser.