|
| 1 | +"""Debug Plugin for EasyEngine""" |
| 2 | + |
| 3 | +from cement.core.controller import CementBaseController, expose |
| 4 | +from cement.core import handler, hook |
| 5 | +from ee.core.logging import Log |
| 6 | +from ee.cli.plugins.site_functions import logwatch |
| 7 | +from ee.core.variables import EEVariables |
| 8 | +import os |
| 9 | +import glob |
| 10 | + |
| 11 | + |
| 12 | +def log_plugin_hook(app): |
| 13 | + # do something with the ``app`` object here. |
| 14 | + pass |
| 15 | + |
| 16 | + |
| 17 | +class EELogController(CementBaseController): |
| 18 | + class Meta: |
| 19 | + label = 'log' |
| 20 | + description = 'Show Nginx, PHP, MySQL log file' |
| 21 | + stacked_on = 'base' |
| 22 | + stacked_type = 'nested' |
| 23 | + arguments = [ |
| 24 | + (['--all'], |
| 25 | + dict(help='Show All logs file', action='store_true')), |
| 26 | + (['--nginx'], |
| 27 | + dict(help='Show Nginx logs file', action='store_true')), |
| 28 | + (['--php'], |
| 29 | + dict(help='Show PHP logs file', action='store_true')), |
| 30 | + (['--mysql'], |
| 31 | + dict(help='Show MySQL logs file', action='store_true')), |
| 32 | + ] |
| 33 | + |
| 34 | + @expose(hide=True) |
| 35 | + def default(self): |
| 36 | + """Default function of debug""" |
| 37 | + self.msg = [] |
| 38 | + |
| 39 | + if ((not self.app.pargs.nginx) and (not self.app.pargs.php) |
| 40 | + and (not self.app.pargs.mysql)): |
| 41 | + self.app.pargs.nginx = True |
| 42 | + self.app.pargs.php = True |
| 43 | + self.app.pargs.mysql = True |
| 44 | + |
| 45 | + if self.app.pargs.nginx: |
| 46 | + self.msg = self.msg + ["/var/log/nginx/*error.log"] |
| 47 | + if self.app.pargs.php: |
| 48 | + open('/var/log/php5/slow.log', 'a').close() |
| 49 | + open('/var/log/php5/fpm.log', 'a').close() |
| 50 | + self.msg = self.msg + ['/var/log/php5/slow.log', |
| 51 | + '/var/log/php5/fpm.log'] |
| 52 | + if self.app.pargs.mysql: |
| 53 | + # MySQL debug will not work for remote MySQL |
| 54 | + if EEVariables.ee_mysql_host is "localhost": |
| 55 | + if os.path.isfile('/var/log/mysql/mysql-slow.log'): |
| 56 | + self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] |
| 57 | + else: |
| 58 | + Log.error(self, "Unable to find MySQL slow log file," |
| 59 | + "Please generate it using commnad ee debug " |
| 60 | + "--mysql") |
| 61 | + else: |
| 62 | + Log.warn(self, "Remote MySQL found, EasyEngine is not able to" |
| 63 | + "show MySQL log file") |
| 64 | + |
| 65 | + watch_list = [] |
| 66 | + for w_list in self.msg: |
| 67 | + watch_list = watch_list + glob.glob(w_list) |
| 68 | + |
| 69 | + logwatch(self, watch_list) |
| 70 | + |
| 71 | + |
| 72 | +def load(app): |
| 73 | + # register the plugin class.. this only happens if the plugin is enabled |
| 74 | + handler.register(EELogController) |
| 75 | + # register a hook (function) to run after arguments are parsed. |
| 76 | + hook.register('post_argument_parsing', log_plugin_hook) |
0 commit comments