Advertisement
KeplerBR

Untitled

Jun 15th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.06 KB | None | 0 0
  1. # logDaBandaRestart plugin by imikelance/marcelofoxes/KeplerBR
  2. # Acknowledgments: EternalHarvest
  3. #
  4. #
  5. # 23:20 sexta-feira, 8 de junho de 2012
  6. #    - Make name file of logs
  7. #    - In the logs show the origin of the message
  8. #    - Fix bug of time and edited colors
  9. #
  10. # 23:42 segunda-feira, 6 de fevereiro de 2012
  11. #    - released !
  12. #
  13. # This source code is licensed under the
  14. # GNU General Public License, Version 2.
  15. # See http://www.gnu.org/licenses/gpl.html
  16.  
  17. package logDaBandaRestart;
  18.  
  19. use strict;
  20.  
  21. use Plugins;
  22. use Commands;
  23. use Log qw( warning message error );
  24. use Settings;
  25. use Globals;
  26. use Misc;
  27.  
  28. use constant {
  29.     PLUGINNAME                =>    "logDaBandaRestart",
  30. };
  31.  
  32.  
  33. #-----------------
  34. # Plugin: settings
  35. #-----------------
  36. Plugins::register(PLUGINNAME, "check your logs folder !", \&unload);
  37.  
  38. # Log hook
  39. my $logHook = Log::addHook(\&on_Log, PLUGINNAME);
  40.  
  41. #-----------------------------
  42. # File: Make name file of logs
  43. #-----------------------------
  44.   my $arqui;
  45.  
  46.     if ($config{'NoRestartFile'}) {
  47.         $arqui = 'console.html';
  48.     } else {
  49.         my $DataLocal = localtime(time());
  50.         my @Data = split(/ +/,$DataLocal);
  51.         $arqui = 'console ' . $Data[2] . ' ' . $Data[1] . ' ' . $Data[4] . ".html";
  52.     }
  53.  
  54. #---------------
  55. # Plugin: unload
  56. #---------------
  57. sub unload {
  58.    Log::delHook($logHook);
  59.    undef $logHook;
  60. }
  61.  
  62. #-------------
  63. # Log: handler
  64. #-------------
  65.  
  66. sub on_Log {
  67.     my ($type, $domain, $level, $globalVerbosity, $message, $user_data) = @_;
  68.    
  69.     if ($level <= $globalVerbosity) {
  70.     my $msgColor;
  71.     if (defined $consoleColors{$type}{$domain}) {
  72.             $msgColor = $consoleColors{$type}{$domain};
  73.         } elsif ($type eq "warning") {
  74.             $msgColor = $consoleColors{warning}{default};
  75.         } elsif ($type eq "error") {
  76.             $msgColor = $consoleColors{error}{default};
  77.         } elsif ($type eq "debug") {
  78.             $msgColor = $consoleColors{debug}{default};
  79.         } else {
  80.             $msgColor = 'grey';
  81.     }
  82.    
  83.     $message =~ s/(\r\n|\n|\r)+/<\/br>/g;
  84.    
  85.     my $hor = localtime();
  86.     my $message2 ="<span class=\"".$msgColor."\">[" . $domain . "][" . $hor . "] ".$message."</span>";
  87.    
  88.     open(F, ">>:utf8", "$Settings::logs_folder/" . $arqui);
  89.         if(-z "$Settings::logs_folder/". $arqui) {
  90.             print F q(
  91. <head><style type="text/css">
  92.  
  93. body {
  94.     background-color: black;
  95.     font-family: "Lucida Console";
  96.     font-weight: bold;
  97.     font-size: 12px;
  98. }
  99.  
  100. .grey {
  101.     color: #c0c0c0;
  102. }
  103.  
  104. .yellow {
  105.     color: #ffff00;
  106. }
  107.  
  108. .darkgreen {
  109.     color: #008000;
  110. }
  111.  
  112. .green {
  113.     color: #00FF00;
  114. }
  115.  
  116. .white {
  117.     color: #FFFFFF;
  118. }
  119.  
  120. .red {
  121.     color: #FF0000;
  122. }
  123.  
  124. .cyan {
  125.     color: #00FFFF;
  126. }
  127.  
  128. .darkmagenta {
  129.     color: #800080;
  130. }
  131.  
  132. .magenta {
  133.     color: #ff00ff;
  134. }
  135.  
  136. .blue {
  137.     color: #0000ff;
  138. }
  139.  
  140. .darkcyan {
  141.     color: #008080;
  142. }
  143.  
  144. .brown {
  145.     color: #808000;
  146. }
  147.  
  148.  </style>
  149.  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  150.  </head>
  151.  );
  152.         }
  153.         print F $message2."\n";
  154.         close(F);
  155.     }
  156.    
  157. }
  158.  
  159. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement