ó à@Qc@s"dZddlZddlmZmZmZmZmZddlZddlm Z m Z ddl m Z m Z mZmZmZddlmZmZmZmZmZddlmZmZmZmZmZmZejje ƒZ!dej"fd „ƒYZ#d ej"fd „ƒYZ$dS( sÉ How to handle MySQL logs ************************* Among other things this module needs to establish: 1. Which of the logs (if any) are enabled. 2. Whether the output of the enabled logs are stored in a table or in a log file. Determining the state of the logs ----------------------------------- There are two possible scenarios: the server is down: In this case all logs are assumed to be **disabled** since the server won't be logging anything unless it's running. the server is up: Starting with MySQL Server 5.1.29 the relevant server variables changed. This derives in two new scenarios: server version < 5.1.29: :general query log: The state of this log is reflected in the server variable ``log`` which will be set to ``'OFF'`` if the log is disabled or to either ``'ON'`` or to ``'1'`` or to a file path if the log is enabled. :slow query log: Its state is reflected in the server variable ``log_slow_queries`` which will be set to ``'OFF'`` if the log is disabled or to ``'ON'`` or to ``'1'`` if the log is enabled. :error log: Its state is reflected in the server variable ``log_error`` which will be set to ``''`` (the empty string) if the log is disabled or to the path to the error log file if the log is enabled. .. note:: The error logs are not going to be written to the error log file if the server was started with the ``--console`` command line option on Windows, even if ``log_error`` has a path set up. In this case error logs are written to stderr. It seems that there's no way to query the server to determine if this ``--console`` option is in place. .. note:: The ``log_slow_queries`` and ``log`` variable were removed in MySQL Server 5.6. server version >= 5.1.29: :general query log: If enabled the ``general_log`` variable will be set to ``'ON'`` or to ``'1'``. Otherwise it will be set to ``'OFF'`` or to ``'0'``. :slow query log: If enabled the ``slow_query_log`` variable will be set to ``'ON'`` or to ``'1'``. Otherwise it will be set to ``'OFF'`` or to ``'0'``. :error log: Its state is reflected in the server variable ``log_error`` as explained for server version < 5.1.29. .. note:: For MySQL Server versions >= 5.1.6, if the variable ``log_output`` contains the value ``'NONE'``, the general query log and the slow query log will not record any new log entry. The general log can also be disabled by setting to ``'1'`` the session variable ``sql_log_off``. Determining where the logs are being written --------------------------------------------- Starting from MySQL Server 5.1.6 there's the possibility of sending the logs from the general query log or from the slow query log to a server table instead of to a log file. This is controlled by the value of the variable ``log_output`` which can be a combination of the values ``'FILE'`` (log into log files), ``'TABLE'`` (log into a server table) or ``'NONE'`` (don't log). If given, ``'NONE'`` takes precedence over the other values. .. warning:: For MySQL Server versions older than 5.1.29 there's no reliable way to know where the general and slow query logs are being written (if they are logged to a file). Their default values are ``$datadir + $hostname + '.log'`` and ``$datadir + $hostname + '-slow.log'``, respectively. This can be changed in the command line or in the configuration file and the real paths will not be exposed in any server variable. Starting from MySQL Server 5.1.29 the paths to the general and slow query log files are stored in the ``general_query_log_file`` and in the``slow_query_log_file`` variables, respectively. *The server creates the file in the data directory unless an absolute path name is given to specify a different directory.* Use cases for the server logs --------------------------------- 1. The server is running. All logs are enabled and WB can precisely determine their sources. Every log is shown in its corresponding tab. 2. The ``log_output`` server variable contains both ``'FILE'`` and ``'TABLE'``. WB will select on a per log basis which source should be chosen. Will select table logs if the server is local or if the server is remote and any of these happen: * Cannot reliably determine the paths to the log file. * The user running WB has no read permissions on the log file. * The log file does not exist. * The user explicitly requested to read from log table. 3. ``log_output`` contains ``'NONE'``. Nonetheless WB will check for log sources and will show them, alerting the user about log not being updated because of that. *What to do if there are log files and log tables available in this case?* 4. The server is logging to files and WB can precisely determine their paths but the log file is missing in the file system. The situation will be reported to the user (advising him to ``FLUSH LOGS`` or restart the server and start querying) The log will not be shown as long as this situation persists. 5. The server is logging to tables and the connection to the server is lost. If the server is also logging to files, and a log file exists in the file system, the log file will be shown and the user will be warned about this change. 6. The server is logging to files and WB cannot precisely determine the path to the log file (i.e. server version < 5.1.29). WB will try to get the path from these sources in this order: 1. The server's configuration file. 2. The default path assumed by the server when no log path is specified. If no such file is found in the file system the log will not be shown. 7. The user changed the source of a log or the path to a log file while WB was showing the previous source/path. WB will switch to the new source/path and will inform the user of the change. 8. [Postponed] The user clicks on a *Add new log* button. A dialog will be shown in which the user will select the type of log to be added (error, general or slow), the log source (a database table or a log file) and the name of the log table/file. A new tab showing the user selected log will be shown and will persist during the session or until the user clicks on the tab's *Close* button. iÿÿÿÿN(tnewBoxtnewLabeltnewTreeNodeViewt newTabViewt newButton(tnot_running_warning_labeltnot_running_warning_label_text(tGeneralQueryLogReadertSlowQueryLogReadertGeneralLogFileReadertSlowLogFileReadertErrorLogFileReader(tLogFileAccessErrort ServerIOErrortOperationCancelledErrortInvalidPasswordErrortlog_error_decorator(tlog_infot log_errort log_warningt log_debugt log_debug2t log_debug3tLogViewcBsheZdZd„Zed„ƒZd„Zd d„Zd„Z d„Z d„Z d„Z d „Z RS( s| Main front end view class for displaying log entries. Each page in the Tab View is an instance of this class. cGs€tt|ƒjtƒ|jƒ|jƒ||_||_||_d|_ d|_ d|_ d|_ d|_|jƒdS(s® The arguments following BackendLogReaderClass will be passed to BackendLogReaderClass to instantiate it in order to get a log reader object. N(tsuperRt__init__tFalset set_managedtset_release_on_addtownertBackendLogReaderClasstargstNonet log_readert error_boxttreetbboxt warning_boxt update_ui(tselfRRR((s..\modules\wb_admin_logs.pyR¼s          cCsÂ|jr%|j|jƒd|_nttƒ|_|jjdƒtt|ƒƒ}|jj|t t ƒt ƒ}|j dƒ|jj|t t ƒ|j |j ƒ|j|jt tƒdS(Nis Try again(R"tremoveR RtTruet set_spacingRtstrtaddRRtset_texttadd_clicked_callbackR&(R'terrort error_labelttry_again_button((s..\modules\wb_admin_logs.pyt _show_errorÒs    c CsL|jr%|j|jƒd|_n|jrJ|j|jƒd|_n|jro|j|jƒd|_n|jr”|j|jƒd|_n|jdƒ|jdƒy|j|j Œ|_ Wn3t t t tttfk rü}|j|ƒdSX|j jrittƒ|_|jjdƒt|j jƒ}|jj|ttƒ|j|jttƒnttjƒ|_|jjtjƒx8|j jD]*}|jjtj|d|dtƒq›W|jj ƒ|j|jttƒttƒ|_|jjdƒ|j!|jttƒtdƒ|_"|jj|j"ttƒt#ƒ|_$|j$j%dƒ|jj|j$ttƒ|j$j&|j'ƒt#ƒ|_(|j(j%dƒ|jj|j(ttƒ|j(j&|j)ƒt#ƒ|_*|j*j%dƒ|jj|j*ttƒ|j*j&|j+ƒt#ƒ|_,|j,j%dƒ|jj|j,ttƒ|j,j&|j-ƒt#ƒ|_.|j.j%d ƒ|jj|j.ttƒ|j.j&|j/ƒt#ƒ|_0|j0j%d ƒ|jj|j0ttƒ|j0j&|j1ƒy|j1|j j2ƒƒWn2t t t tttfk rG}|j|ƒnXdS( Niiits Copy Selecteds<s>>tRefresh(3R"R(R R#R$R%t set_paddingR*RRR!R R RRtIOErrort ValueErrorR2tpartial_supportRR)RR,RRtmformst TreeFlatListtset_selection_modetTreeSelectMultiplet column_specst add_columntStringColumnTypet end_columnstadd_endt range_labelRt view_buttonR-R.t copy_detailst bof_buttontgo_boft back_buttontgo_backt next_buttontgo_nextt eof_buttontgo_eoftrefresh_buttontrefreshtlast(R'R/t warning_labeltcolspec((s..\modules\wb_admin_logs.pyR&ás†          !          !c CsK|jrGy|jjƒ|s1|jjƒ}n|jjƒxP|D]H}|jjƒ}x0t|ƒD]"\}}|j||jƒƒqgWqEW|j j |jj ƒƒ|j j |jjƒƒ|jj |jjƒƒ|jj |jjƒƒ|jj |jjƒƒWqGttttttfk rC}|j|ƒqGXndS(N(R!RPtcurrentR#tcleartadd_nodet enumeratet set_stringtstripRDR-t range_textRGt set_enabledt has_previousRIRMthas_nextRKR R RRR8R9R2(R'trecordstrectrowtidxtcolR/((s..\modules\wb_admin_logs.pyRP9s"    !cCsh|jjƒ}g}x*|D]"}|j|j|jjƒƒqW|rdtjjdj |ƒƒndS(Ns ( R#t get_selectiontappendt get_stringR!t detail_columnR;t Utilitiestset_clipboard_texttjoin(R't selectionttexttnode((s..\modules\wb_admin_logs.pyRFMs   c CsSy|j|jjƒƒWn2ttttttfk rN}|j |ƒnXdS(N( RPR!tfirstR R RRR8R9R2(R'R/((s..\modules\wb_admin_logs.pyRHZs!c CsSy|j|jjƒƒWn2ttttttfk rN}|j |ƒnXdS(N( RPR!RQR R RRR8R9R2(R'R/((s..\modules\wb_admin_logs.pyRN`s!c Csny5|jjƒr!|jjƒnd}|j|ƒWn2ttttt t fk ri}|j |ƒnXdS(N( R!R\tpreviousR RPR R RRR8R9R2(R'R^R/((s..\modules\wb_admin_logs.pyRJfs $!c Csny5|jjƒr!|jjƒnd}|j|ƒWn2ttttt t fk ri}|j |ƒnXdS(N( R!R]tnextR RPR R RRR8R9R2(R'R^R/((s..\modules\wb_admin_logs.pyRLms $!N(t__name__t __module__t__doc__RRR2R&R RPRFRHRNRJRL(((s..\modules\wb_admin_logs.pyR¶s  X    t WbAdminLogscBsheZeZd„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z d„Z d „Z RS( cCsttt|ƒjtƒ|jj|dƒ|jƒ||_||_||_ t|_ |j j |dddƒdS(Ntpaget MANAGEMENTs Server Logstadmin_server_logs_win( RRsRRt ui_profilet apply_styleRtctrl_betserver_profilet main_viewtdisable_log_refreshtadd_content_page(R'RyRzR{((s..\modules\wb_admin_logs.pyRxs     cCsˆtƒ|_|j|jttƒ|jjtƒttƒ|_|j|jttƒd|_ d|_ d|_ d|_ d|_ dS(N(RtwarningR,RR)tshowRttabViewR tgeneral_log_tabt slow_log_tabtgeneral_file_log_tabtslow_file_log_tabterror_file_log_tab(R'((s..\modules\wb_admin_logs.pyt create_ui‚s     cs¶i}ˆjjƒr²ˆjjdkr¥y&ˆjjdƒ}|jƒsL|SWn|SX|jdƒdkrsdndˆj_tt d ˆj j ˆjjfƒq²y&ˆjjd ƒ}|jƒsÊ|SWn|SX|jdƒˆj_dˆjjkr’d ˆjjkr’‡fd †}ˆjj s_d |d   "! .! .! ""cCsÕ|jƒ}|jdƒ|jjs4d|j_nd|jjkrY|jddƒnX|jjdkrˆ|jdƒ|jdƒn)|jjdkr·|jdƒ|jdƒnú|jjdksÛ|jjdkrtddd d gƒ}g}|jjƒsd d g}nF|j|d dkr3d ndƒ|j|d dkrVd ndƒ|jt |t|ƒƒŒ|jt |ƒŒn!d |jj}|j |ƒdS|j j t ƒ|jj tƒdS(NR³s TABLE,FILERŠR‹R‰s FILE,TABLER¯R°R±R²R™RšsÄWe have detected a problem in your current Log Destination. It is set to %s. Please refer to the documentation for further information: http://dev.mysql.com/doc/refman/5.1/en/log-destinations.html(R¬R¼RzR¢R·tsetRyRRdttupleR®R~RRR€R)(R'Rªttabst to_be_addedR­((s..\modules\wb_admin_logs.pyR&s4     $## cCsž|jjdƒ|js/|jƒt|_n|jƒy|jƒWnPtk r™}tj j dd|dddƒ}|tj kršt|_ qšnXdS(Ns Server Logss Log Refreshs8An error occurred while displaying MySQL server logs: %stIgnoretCancelR3( R{tset_content_labelt ui_createdR†R)R&RPt ExceptionR;Rgt show_warningt ResultCancelR|(R'tetr((s..\modules\wb_admin_logs.pytpage_activated?s    "cCs |jr dS|jjƒrQ|jr5|jjƒn|jrQ|jjƒqQn|jrj|jjƒn|jrƒ|jjƒn|jrœ|jjƒndS(N( R|RyRRRPR‚RƒR„R…(R'((s..\modules\wb_admin_logs.pyRPMs      cCsdS(N((R'((s..\modules\wb_admin_logs.pyt do_refresh\s(RpRqRRÄRR†R¬R®R·R¼R&RÊRPRË(((s..\modules\wb_admin_logs.pyRsus  C   ( (  (%RrtosR;RRRRRtwb_admin_utilsRRt wb_log_readerRRR R R t wb_commonR R RRRtgrtRRRRRRR•tbasenamet__file__R£tBoxRRs(((s..\modules\wb_admin_logs.pyt¨s ( ((.¿