Plugin Directory

Changeset 2354412


Ignore:
Timestamp:
08/07/2020 07:36:14 AM (6 years ago)
Author:
pressmaninc
Message:

V1.1

Location:
app-log/trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • app-log/trunk/README.md

    r2352080 r2354412  
    88# How to use
    99There are 2 ways to use the plugin
    10 1. Call the ready-to-use applog function\
    11     By calling the function `applog`, the message will written to the log file.\
    12     `applog( 'Hello' ) ` will output 'Hello' in the log file
     101. Call the ready-to-use functions below
     11   - `applog( message, directory, log level )`
     12   - `applog_trace( message, directory )`
     13   - `applog_debug( message, directory )`
     14   - `applog_info( message, directory )`
     15   - `applog_warn( message, directory )`
     16   - `applog_error( message, directory )`
     17   - `applog_fatal( message, directory )`
    1318
    14 2. Use the 'app_log' hook\
     19    The directory parameter refers to a subdirectory inside the plugin directory. Default value is empty. If it is empty, log will be stored in the log directory path displayed in the settings page.
     20
     21    The log level parameter in the `applog` function has a default value of 'TRACE'. If no value or an invalid value is passed, log level is automatically set to 'TRACE'.
     22
     23    By calling any of the functions above, the message will written to the log file.\
     24    For example, `applog( 'Hello' ) ` will output 'Hello' with TRACE log level in the log file
     25
     262. Use the 'applog' hook\
    1527    If another plugin will use this to output logs, it is best to use this option instead of calling `applog` function to avoid Fatal Error in case this plugin is deactivated.\
    16     `do_action( 'app_log' , 'Hello' )` will output 'Hello' in the log file
     28    `do_action( 'applog' , 'Hello' )` will output 'Hello' with TRACE log level in the log file
    1729
    1830Log files are listed on the Administrator Dashboard page for easier viewing and deleting.
  • app-log/trunk/admin/aplg-dashboard.php

    r2352236 r2354412  
    7272        $list_html       = '';
    7373
    74         if ( $path_to_log_dir !== FALSE && file_exists( $path_to_log_dir ) ) {
     74        if ( $path_to_log_dir !== false && file_exists( $path_to_log_dir ) ) {
    7575            // Link to the actual file
    7676            $url_to_log_dir = '';
     
    8181            // Link for file deletion
    8282            $url_for_delete_log_dir = wp_nonce_url( admin_url( '/' ), Aplg_Settings::DELETE_KEY ) . '&' . Aplg_Settings::DELETE_KEY . '=';
    83             $delete_label = __( 'Delete', 'aplg' );
     83            $delete_label           = __( 'Delete', 'aplg' );
    8484
    8585            $files = scandir( $path_to_log_dir );
     
    104104        if ( $list_html === '' ) {
    105105            $list_html = '<span>' . __( 'No logs found.', 'aplg' ) . '</span>';
    106         } 
     106        }
    107107
    108108        self::create_widget( $list_html, $path_to_log_dir );
     
    218218        }
    219219
    220         if ( ! isset( $_GET [ Aplg_Settings::DELETE_KEY . '_done' ]) || $_GET [ Aplg_Settings::DELETE_KEY . '_done' ] == '' ) {
    221             return;
    222         }
    223        
     220        if ( ! isset( $_GET [ Aplg_Settings::DELETE_KEY . '_done' ] ) || $_GET [ Aplg_Settings::DELETE_KEY . '_done' ] == '' ) {
     221            return;
     222        }
     223
    224224        $deleted_log = urldecode( $_GET [ Aplg_Settings::DELETE_KEY . '_done' ] );
    225         //Data from GET not sanitized but decoded instead since the correct filename is needed to confirm if file is correctly deleted or not
    226         $log_dir     = realpath( Aplg_Settings::get_path_to_logdir() );
    227         $file_path   = $log_dir . '/' . $deleted_log;
    228         if ( $log_dir !== FALSE && ! file_exists( $file_path ) ) {
     225        // Data from GET not sanitized but decoded instead since the correct filename is needed to confirm if file is correctly deleted or not
     226        $log_dir   = realpath( Aplg_Settings::get_path_to_logdir() );
     227        $file_path = $log_dir . '/' . $deleted_log;
     228        if ( $log_dir !== false && ! file_exists( $file_path ) ) {
    229229            self::$notices = array(
    230230                'type'    => 'success',
     
    240240    public function display_notice() {
    241241        ?>
    242         <div class="notice notice-<?php echo self::$notices[ 'type' ]; ?>">
    243             <p><?php echo self::$notices[ 'message' ]; ?></p>
     242        <div class="notice notice-<?php echo self::$notices['type']; ?>">
     243            <p><?php echo self::$notices['message']; ?></p>
    244244        </div>
    245245        <?php
  • app-log/trunk/app-log.php

    r2352236 r2354412  
    44Plugin URI:
    55Description: A simple logger for debugging.
    6 Version: 1.0.1
     6Version: 1.1
    77Author: PRESSMAN
    88Author URI: https://www.pressman.ne.jp/
     
    1717}
    1818
    19 function applog( $message, $dirname = '' ) {
    20     Aplg_Logger::log( $message, $dirname );
    21 }
     19require_once dirname( __FILE__ ) . '/app-log-functions.php';
    2220
    2321/**
     
    3836
    3937        // Load text domain
    40         add_action( 'init', array( $this, 'load_aplg_textdomain' ) );
    41         // Allow other plugins to output log using 'app_log' hook
    42         add_action( 'app_log', array( 'Aplg_Logger', 'log' ), 10 );
     38        add_action( 'init', array( $this, 'load_aplg_textdomain' ), 10 );
     39        // Allow other plugins to output log using 'applog' hook
     40        add_action( 'applog', array( 'Aplg_Logger', 'log' ), 10, 3 );
    4341    }
    4442
  • app-log/trunk/classes/class-aplg-logger.php

    r2352080 r2354412  
    1111class Aplg_Logger {
    1212    const LOG_AUTO_DELETE_PROBABILITY = 10; // Auto-delete will be run within 10% probability
     13    const LOG_LEVEL                   = array(
     14        'TRACE_LOG' => 'TRACE',
     15        'DEBUG_LOG' => 'DEBUG',
     16        'INFO_LOG'  => 'INFO',
     17        'WARN_LOG'  => 'WARN',
     18        'ERROR_LOG' => 'ERROR',
     19        'FATAL_LOG' => 'FATAL',
     20    );
     21    const ALLOWED_FILE_EXT            = array(
     22        'LOG' => '.log',
     23        'TXT' => '.txt',
     24    );
    1325
    1426    /**
     
    1830     * @param string $dirname
    1931     */
    20     public static function log( $message, $dirname = '' ) {
     32    public static function log( $message, $dirname = '', $log_level = self::LOG_LEVEL['TRACE_LOG'] ) {
     33        if ( ! in_array( $log_level, array_values( self::LOG_LEVEL ) ) ) {
     34            $log_level = self::LOG_LEVEL['TRACE_LOG'];
     35        }
    2136
    2237        if ( ! is_string( $message ) ) {
     
    2439        }
    2540
    26         $message  = date_i18n( 'Y-m-d H:i:s' ) . ' ' . $message . "\n";
    27         $filename = date_i18n( 'Ymd' ) . '.log';
     41        $log_message = '[' . date_i18n( 'Y-m-d H:i:s' ) . '] [' . str_pad( $log_level, 5, ' ' ) . '] ';
     42        $process_id  = getmypid();
     43        if ( $process_id ) {
     44            $log_message .= '(Process ID: ' . $process_id . ') ';
     45        }
     46        $log_message .= $message . "\n";
     47        $log_file_ext = apply_filters( 'app_log_file_ext', self::ALLOWED_FILE_EXT['LOG'] );
     48        if ( strpos( $log_file_ext, '.' ) !== 0 ) {
     49            $log_file_ext = '.' . $log_file_ext;
     50        }
     51        if ( ! in_array( $log_file_ext, self::ALLOWED_FILE_EXT ) ) {
     52            $log_file_ext = self::ALLOWED_FILE_EXT['LOG'];
     53        }
     54
     55        $filename = date_i18n( 'Ymd' ) . $log_file_ext;
    2856        $log_dir  = Aplg_Settings::get_path_to_logdir( $dirname );
    2957
    3058        // Create directory if it doesn't exist
    31         if ( realpath( $log_dir ) === FALSE || ! is_dir( $log_dir ) ) {
     59        if ( realpath( $log_dir ) === false || ! is_dir( $log_dir ) ) {
    3260            $flag = mkdir( $log_dir, 0777 );
    3361        }
     
    3866        $log_file = realpath( $log_dir ) . '/' . $filename;
    3967        $fp       = fopen( $log_file, 'a' );
    40         fwrite( $fp, $message );
     68        fwrite( $fp, $log_message );
    4169        fclose( $fp );
    4270
  • app-log/trunk/lang/aplg-ja.po

    r2352236 r2354412  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: App Log 1.01\n"
     5"Project-Id-Version: App Log 1.1\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/app-log\n"
    77"Language-Team: \n"
     
    1010"Content-Transfer-Encoding: 8bit\n"
    1111"POT-Creation-Date: 2020-07-29T02:35:19+00:00\n"
    12 "PO-Revision-Date: 2020-08-04T05:31:28+00:00\n"
     12"PO-Revision-Date: 2020-08-07T06:01:23+00:00\n"
    1313"X-Generator: Poedit 2.3.1\n"
    1414"X-Domain: aplg\n"
     
    6666msgstr "不正なアクセス"
    6767
    68 #: admin/aplg-dashboard.php:231 classes/class-aplg-logger.php:94
     68#: admin/aplg-dashboard.php:231 classes/class-aplg-logger.php:122
    6969msgid "%s successfully deleted."
    7070msgstr "%sを正常に削除されました。"
     
    8282msgstr "メールログ 有効化・無効化"
    8383
    84 #: classes/class-aplg-logger.php:86 classes/class-aplg-logger.php:99
     84#: classes/class-aplg-logger.php:114 classes/class-aplg-logger.php:127
    8585msgid "Failed to delete log."
    8686msgstr "削除処理は失敗しました。"
  • app-log/trunk/lang/aplg.pot

    r2352236 r2354412  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: App Log 1.01\n"
     5"Project-Id-Version: App Log 1.1\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/app-log\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1111"Content-Transfer-Encoding: 8bit\n"
    1212"POT-Creation-Date: 2020-07-29T02:35:19+00:00\n"
    13 "PO-Revision-Date: 2020-08-04T05:31:28+00:00\n"
     13"PO-Revision-Date: 2020-08-07T06:01:23+00:00\n"
    1414"X-Generator: WP-CLI 2.4.0\n"
    1515"X-Domain: aplg\n"
     
    6666
    6767#: admin/aplg-dashboard.php:231
    68 #: classes/class-aplg-logger.php:94
     68#: classes/class-aplg-logger.php:122
    6969msgid "%s successfully deleted."
    7070msgstr ""
     
    8383msgstr ""
    8484
    85 #: classes/class-aplg-logger.php:86
    86 #: classes/class-aplg-logger.php:99
     85#: classes/class-aplg-logger.php:114
     86#: classes/class-aplg-logger.php:127
    8787msgid "Failed to delete log."
    8888msgstr ""
  • app-log/trunk/readme.txt

    r2352236 r2354412  
    55Tested up to: 5.4.2
    66Requires PHP: 5.6.20
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2121
    2222== Changelog ==
     23= 1.1 =
     24* added log level
     25* changed hook name from app_log to applog
     26* added filter to allow changing of log file extension
     27
    2328= 1.0 =
    2429* first version.
Note: See TracChangeset for help on using the changeset viewer.