Changeset 2354412
- Timestamp:
- 08/07/2020 07:36:14 AM (6 years ago)
- Location:
- app-log/trunk
- Files:
-
- 1 added
- 8 edited
-
README.md (modified) (1 diff)
-
admin/aplg-dashboard.php (modified) (5 diffs)
-
app-log-functions.php (added)
-
app-log.php (modified) (3 diffs)
-
classes/class-aplg-logger.php (modified) (4 diffs)
-
lang/aplg-ja.mo (modified) (previous)
-
lang/aplg-ja.po (modified) (4 diffs)
-
lang/aplg.pot (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
app-log/trunk/README.md
r2352080 r2354412 8 8 # How to use 9 9 There 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 10 1. 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 )` 13 18 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 26 2. Use the 'applog' hook\ 15 27 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 file28 `do_action( 'applog' , 'Hello' )` will output 'Hello' with TRACE log level in the log file 17 29 18 30 Log files are listed on the Administrator Dashboard page for easier viewing and deleting. -
app-log/trunk/admin/aplg-dashboard.php
r2352236 r2354412 72 72 $list_html = ''; 73 73 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 ) ) { 75 75 // Link to the actual file 76 76 $url_to_log_dir = ''; … … 81 81 // Link for file deletion 82 82 $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' ); 84 84 85 85 $files = scandir( $path_to_log_dir ); … … 104 104 if ( $list_html === '' ) { 105 105 $list_html = '<span>' . __( 'No logs found.', 'aplg' ) . '</span>'; 106 } 106 } 107 107 108 108 self::create_widget( $list_html, $path_to_log_dir ); … … 218 218 } 219 219 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 224 224 $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 not226 $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 ) ) { 229 229 self::$notices = array( 230 230 'type' => 'success', … … 240 240 public function display_notice() { 241 241 ?> 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> 244 244 </div> 245 245 <?php -
app-log/trunk/app-log.php
r2352236 r2354412 4 4 Plugin URI: 5 5 Description: A simple logger for debugging. 6 Version: 1. 0.16 Version: 1.1 7 7 Author: PRESSMAN 8 8 Author URI: https://www.pressman.ne.jp/ … … 17 17 } 18 18 19 function applog( $message, $dirname = '' ) { 20 Aplg_Logger::log( $message, $dirname ); 21 } 19 require_once dirname( __FILE__ ) . '/app-log-functions.php'; 22 20 23 21 /** … … 38 36 39 37 // Load text domain 40 add_action( 'init', array( $this, 'load_aplg_textdomain' ) );41 // Allow other plugins to output log using 'app _log' hook42 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 ); 43 41 } 44 42 -
app-log/trunk/classes/class-aplg-logger.php
r2352080 r2354412 11 11 class Aplg_Logger { 12 12 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 ); 13 25 14 26 /** … … 18 30 * @param string $dirname 19 31 */ 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 } 21 36 22 37 if ( ! is_string( $message ) ) { … … 24 39 } 25 40 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; 28 56 $log_dir = Aplg_Settings::get_path_to_logdir( $dirname ); 29 57 30 58 // 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 ) ) { 32 60 $flag = mkdir( $log_dir, 0777 ); 33 61 } … … 38 66 $log_file = realpath( $log_dir ) . '/' . $filename; 39 67 $fp = fopen( $log_file, 'a' ); 40 fwrite( $fp, $ message );68 fwrite( $fp, $log_message ); 41 69 fclose( $fp ); 42 70 -
app-log/trunk/lang/aplg-ja.po
r2352236 r2354412 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: App Log 1. 01\n"5 "Project-Id-Version: App Log 1.1\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/app-log\n" 7 7 "Language-Team: \n" … … 10 10 "Content-Transfer-Encoding: 8bit\n" 11 11 "POT-Creation-Date: 2020-07-29T02:35:19+00:00\n" 12 "PO-Revision-Date: 2020-08-0 4T05:31:28+00:00\n"12 "PO-Revision-Date: 2020-08-07T06:01:23+00:00\n" 13 13 "X-Generator: Poedit 2.3.1\n" 14 14 "X-Domain: aplg\n" … … 66 66 msgstr "不正なアクセス" 67 67 68 #: admin/aplg-dashboard.php:231 classes/class-aplg-logger.php: 9468 #: admin/aplg-dashboard.php:231 classes/class-aplg-logger.php:122 69 69 msgid "%s successfully deleted." 70 70 msgstr "%sを正常に削除されました。" … … 82 82 msgstr "メールログ 有効化・無効化" 83 83 84 #: classes/class-aplg-logger.php: 86 classes/class-aplg-logger.php:9984 #: classes/class-aplg-logger.php:114 classes/class-aplg-logger.php:127 85 85 msgid "Failed to delete log." 86 86 msgstr "削除処理は失敗しました。" -
app-log/trunk/lang/aplg.pot
r2352236 r2354412 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: App Log 1. 01\n"5 "Project-Id-Version: App Log 1.1\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/app-log\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 11 11 "Content-Transfer-Encoding: 8bit\n" 12 12 "POT-Creation-Date: 2020-07-29T02:35:19+00:00\n" 13 "PO-Revision-Date: 2020-08-0 4T05:31:28+00:00\n"13 "PO-Revision-Date: 2020-08-07T06:01:23+00:00\n" 14 14 "X-Generator: WP-CLI 2.4.0\n" 15 15 "X-Domain: aplg\n" … … 66 66 67 67 #: admin/aplg-dashboard.php:231 68 #: classes/class-aplg-logger.php: 9468 #: classes/class-aplg-logger.php:122 69 69 msgid "%s successfully deleted." 70 70 msgstr "" … … 83 83 msgstr "" 84 84 85 #: classes/class-aplg-logger.php: 8686 #: classes/class-aplg-logger.php: 9985 #: classes/class-aplg-logger.php:114 86 #: classes/class-aplg-logger.php:127 87 87 msgid "Failed to delete log." 88 88 msgstr "" -
app-log/trunk/readme.txt
r2352236 r2354412 5 5 Tested up to: 5.4.2 6 6 Requires PHP: 5.6.20 7 Stable tag: 1. 07 Stable tag: 1.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 21 21 22 22 == 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 23 28 = 1.0 = 24 29 * first version.
Note: See TracChangeset
for help on using the changeset viewer.