Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

115 řádky
2.6 KiB

  1. <?php
  2. namespace OrpheusNET\Logchecker\Command;
  3. use OrpheusNET\Logchecker\Logchecker;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputOption;
  7. use Symfony\Component\Console\Input\InputInterface;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. class AnalyzeCommand extends Command
  10. {
  11. protected function configure()
  12. {
  13. $this
  14. ->setName('analyze')
  15. ->setDescription('analyze log file')
  16. ->setHelp('This command analyzes a log file')
  17. ->addOption('output', null, InputOption::VALUE_NONE, 'Print the HTML log text')
  18. ->addOption('out', 'file', InputOption::VALUE_REQUIRED, 'File to write HTML log text to')
  19. ->addArgument('file', InputArgument::REQUIRED, 'Log file to analyze');
  20. }
  21. protected function execute(InputInterface $input, OutputInterface $output)
  22. {
  23. $filename = $input->getArgument('file');
  24. if (!file_exists($filename)) {
  25. $output->writeln("Invalid file");
  26. return 1;
  27. }
  28. $logchecker = new Logchecker();
  29. $logchecker->newFile($filename);
  30. $logchecker->parse();
  31. $output->writeln('Ripper : ' . $logchecker->getRipper());
  32. $output->writeln('Version : ' . $logchecker->getVersion());
  33. $output->writeln('Score : ' . $logchecker->getScore());
  34. $output->writeln('Checksum: ' . $logchecker->getChecksumState());
  35. $details = $logchecker->getDetails();
  36. if (count($details) > 0) {
  37. $output->writeln('Details :');
  38. foreach ($details as $detail) {
  39. $output->writeln(' ' . $detail);
  40. }
  41. }
  42. if ($input->getOption('output')) {
  43. $output->writeln('');
  44. $output->writeln('Log Text:');
  45. $output->writeln($logchecker->getLog());
  46. }
  47. if ($input->getOption('out')) {
  48. $html_out = <<<HTML
  49. <!DOCTYPE html>
  50. <html lang="en">
  51. <head>
  52. <title>Test</title>
  53. <meta charset="utf-8"/>
  54. <style>
  55. .log1 {
  56. }
  57. .log2 {
  58. color: yellow;
  59. }
  60. .log3 {
  61. color: #0E88C6;
  62. }
  63. .log4 {
  64. font-weight: bold;
  65. }
  66. .log5 {
  67. text-decoration: underline;
  68. }
  69. .good {
  70. font-weight: bold;
  71. color: green;
  72. }
  73. .bad {
  74. font-weight: bold;
  75. color: red;
  76. }
  77. .goodish {
  78. font-weight: bold;
  79. color: #35BF00;
  80. }
  81. .badish {
  82. font-weight: bold;
  83. color: #E5B244;
  84. }
  85. </style>
  86. </head>
  87. <body>
  88. <pre>{$logchecker->getLog()}</pre>
  89. </body>
  90. </html>
  91. HTML;
  92. file_put_contents($input->getOption('out'), $html_out);
  93. }
  94. return 0;
  95. }
  96. }