]> source.dussan.org Git - nextcloud-server.git/commitdiff
merge log into admin
authorRobin Appelman <icewind@owncloud.com>
Mon, 16 Apr 2012 10:21:12 +0000 (12:21 +0200)
committerRobin Appelman <icewind@owncloud.com>
Mon, 16 Apr 2012 10:21:48 +0000 (12:21 +0200)
lib/app.php
lib/log/owncloud.php
lib/util.php
settings/admin.php
settings/js/log.js
settings/templates/admin.php
settings/templates/log.php [deleted file]

index bd432109b235dcc9ac04907c6a4e64d2e0164a96..9f7d23872f3cfa8abcb0d99ad7a173e8b1e96ef2 100755 (executable)
@@ -303,8 +303,6 @@ class OC_App{
                                $settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "settings", "users.php" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" ));
                                // admin apps menu
                                $settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" ));
-                               // admin log menu
-                               $settings[] = array( "id" => "core_log", "order" => 4, "href" => OC_Helper::linkTo( "settings", "log.php" ), "name" => $l->t("Log"), "icon" => OC_Helper::imagePath( "settings", "log.svg" ));
 
                                $settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" ));
                        }
index 0ed30510134407756cd2a57ac21ec77802927583..881c67d2664a67a6e2b23e2ba18740210711c3a6 100644 (file)
@@ -44,7 +44,7 @@ class OC_Log_Owncloud {
         * @param int level
         */
        public static function write($app, $message, $level) {
-               $minLevel=OC_Config::getValue( "loglevel", 2 );
+               $minLevel=min(OC_Config::getValue( "loglevel", OC_Log::WARN ),OC_Log::ERROR);
                if($level>=$minLevel){
                        $entry=array('app'=>$app, 'message'=>$message, 'level'=>$level,'time'=>time());
                        $fh=fopen(self::$logFile, 'a');
@@ -61,6 +61,7 @@ class OC_Log_Owncloud {
         */
        public static function getEntries($limit=50, $offset=0){
                self::init();
+               $minLevel=OC_Config::getValue( "loglevel", OC_Log::WARN );
                $entries=array();
                if(!file_exists(self::$logFile)) {
                        return array();
@@ -71,8 +72,13 @@ class OC_Log_Owncloud {
                }
                $end=max(count($contents)-$offset-1, 0);
                $start=max($end-$limit,0);
-               for($i=$end;$i>$start;$i--) {
-                       $entries[]=json_decode($contents[$i]);
+               $i=$end;
+               while(count($entries)<$limit){
+                       $entry=json_decode($contents[$i]);
+                       if($entry->level>=$minLevel){
+                               $entries[]=$entry;
+                       }
+                       $i--;
                }
                return $entries;
        }
index 2ea392ec31dc896c065ce4a7f5bee4d9e7ffa404..02ac2e505fa330a3966947ffe185d4a03c84ed6c 100644 (file)
@@ -129,23 +129,23 @@ class OC_Util {
                self::$headers[]=array('tag'=>$tag,'attributes'=>$attributes,'text'=>$text);
        }
 
-       /**
-         * formats a timestamp in the "right" way
-         *
-         * @param int timestamp $timestamp
-         * @param bool dateOnly option to ommit time from the result
-         */
-        public static function formatDate( $timestamp,$dateOnly=false){
-                       if(isset($_SESSION['timezone'])){//adjust to clients timezone if we know it
-                               $systemTimeZone = intval(date('O'));
-                               $systemTimeZone=(round($systemTimeZone/100,0)*60)+($systemTimeZone%100);
-                               $clientTimeZone=$_SESSION['timezone']*60;
-                               $offset=$clientTimeZone-$systemTimeZone;
-                               $timestamp=$timestamp+$offset*60;
-                       }
-                       $timeformat=$dateOnly?'F j, Y':'F j, Y, H:i';
-                       return date($timeformat,$timestamp);
-        }
+   /**
+     * formats a timestamp in the "right" way
+     *
+     * @param int timestamp $timestamp
+     * @param bool dateOnly option to ommit time from the result
+     */
+    public static function formatDate( $timestamp,$dateOnly=false){
+               if(isset($_SESSION['timezone'])){//adjust to clients timezone if we know it
+                       $systemTimeZone = intval(date('O'));
+                       $systemTimeZone=(round($systemTimeZone/100,0)*60)+($systemTimeZone%100);
+                       $clientTimeZone=$_SESSION['timezone']*60;
+                       $offset=$clientTimeZone-$systemTimeZone;
+                       $timestamp=$timestamp+$offset*60;
+               }
+               $timeformat=$dateOnly?'F j, Y':'F j, Y, H:i';
+               return date($timeformat,$timestamp);
+    }
 
        /**
         * Shows a pagenavi widget where you can jump to different pages.
index 9ee79002b5e772fdf04e0afa0ae0d50c86266315..a997bad4e3c8553987a73f0ec87ea4194d057dc5 100644 (file)
@@ -10,11 +10,20 @@ OC_Util::checkAdminUser();
 
 OC_Util::addStyle( "settings", "settings" );
 OC_Util::addScript( "settings", "admin" );
+OC_Util::addScript( "settings", "log" );
 OC_App::setActiveNavigationEntry( "admin" );
 
 $tmpl = new OC_Template( 'settings', 'admin', 'user');
 $forms=OC_App::getForms('admin');
+
+$entries=OC_Log_Owncloud::getEntries(3);
+function compareEntries($a,$b){
+       return $b->time - $a->time;
+}
+usort($entries, 'compareEntries');
+
 $tmpl->assign('loglevel',OC_Config::getValue( "loglevel", 2 ));
+$tmpl->assign('entries',$entries);
 $tmpl->assign('forms',array());
 foreach($forms as $form){
        $tmpl->append('forms',$form);
index ae83f0a6283ab2ee569075ec4c44a2c0ce4367cf..bccf2c88269a3d4b020306cf624b18b22f938c9b 100644 (file)
@@ -6,14 +6,15 @@
 
 OC.Log={
        levels:['Debug','Info','Warning','Error','Fatal'],
-       loaded:50,//are initially loaded
+       loaded:3,//are initially loaded
        getMore:function(){
-               $.get(OC.filePath('settings','ajax','getlog.php'),{offset:OC.Log.loaded},function(result){
+               $.get(OC.filePath('settings','ajax','getlog.php'),{offset:OC.Log.loaded,count:10},function(result){
                        if(result.status=='success'){
                                OC.Log.addEntries(result.data);
+                               $('html, body').animate({scrollTop: $(document).height()}, 800);
                        }
                });
-               OC.Log.loaded+=50;
+               OC.Log.loaded+=10;
        },
        addEntries:function(entries){
                for(var i=0;i<entries.length;i++){
index e3fd60fefce44e32d305c13010857a1bfcb556df..38c6042c82ae68fa5022b0c6d75d3a4a452a7241 100644 (file)
@@ -10,8 +10,8 @@ $levels=array('Debug','Info','Warning','Error','Fatal');
        echo $form;
 };?>
 <fieldset class="personalblock">
-       <legend><strong><?php echo $l->t('Log level');?></strong></legend>
-       <select name='loglevel' id='loglevel'>
+       <legend><strong><?php echo $l->t('Log');?></strong></legend>
+       Log level: <select name='loglevel' id='loglevel'>
                <option value='<?php echo $_['loglevel']?>'><?php echo $levels[$_['loglevel']]?></option>
                <?php for($i=0;$i<5;$i++):
                        if($i!=$_['loglevel']):?>
@@ -19,4 +19,23 @@ $levels=array('Debug','Info','Warning','Error','Fatal');
                        <?php endif;
                endfor;?>
        </select>
+       <table id='log'>
+       <?php foreach($_['entries'] as $entry):?>
+               <tr>
+                       <td>
+                               <?php echo $levels[$entry->level];?>
+                       </td>
+                       <td>
+                               <?php echo $entry->app;?>
+                       </td>
+                       <td>
+                               <?php echo $entry->message;?>
+                       </td>
+                       <td>
+                               <?php echo OC_Util::formatDate($entry->time);?>
+                       </td>
+               </tr>
+       <?php endforeach;?>
+</table>
+<input id='moreLog' type='button' value='<?php echo $l->t('More');?>...'></input>
 </fieldset>
diff --git a/settings/templates/log.php b/settings/templates/log.php
deleted file mode 100644 (file)
index da5defc..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php /**
- * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
- * This file is licensed under the Affero General Public License version 3 or later.
- * See the COPYING-README file.
- */
-$levels=array('Debug','Info','Warning','Error','Fatal');
-?>
-
-<div id="controls">
-       
-</div>
-<table id='log'>
-       <?php foreach($_['entries'] as $entry):?>
-               <tr>
-                       <td>
-                               <?php echo $levels[$entry->level];?>
-                       </td>
-                       <td>
-                               <?php echo $entry->app;?>
-                       </td>
-                       <td>
-                               <?php echo $entry->message;?>
-                       </td>
-                       <td>
-                               <?php echo $l->l('datetime',$entry->time);?>
-                       </td>
-               </tr>
-       <?php endforeach;?>
-</table>
-<input id='moreLog' type='button' value='<?php echo $l->t('More');?>...'></input>