Plugin Directory

Changeset 1239660


Ignore:
Timestamp:
09/07/2015 10:37:38 AM (11 years ago)
Author:
japh
Message:

Update to commit 974073d from git@…:Japh/stream-to-papertrail.git

Location:
stream-to-papertrail
Files:
7 added
7 edited

Legend:

Unmodified
Added
Removed
  • stream-to-papertrail/assets/banner-1544x500.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • stream-to-papertrail/assets/banner-772x250.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • stream-to-papertrail/assets/icon-128x128.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • stream-to-papertrail/assets/icon-256x256.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • stream-to-papertrail/trunk/inc/class-stream-papertrail-api.php

    r1239401 r1239660  
    5151                    'default'     => 'stream',
    5252                ),
     53                array(
     54                    'name'        => 'enable_colorization',
     55                    'title'       => esc_html__( 'Colorization', 'stream-papertrail' ),
     56                    'type'        => 'checkbox',
     57                    'desc'        => esc_html__( '', 'stream-papertrail' ),
     58                    'after_field' => esc_html__( 'Enabled', 'stream-papertrail' ),
     59                    'default'     => 1,
     60                ),
    5361            ),
    5462        );
     
    8593        $component   = $this->options['papertrail_component'];
    8694
    87         $syslog_message = '<22>' . date( 'M d H:i:s ' ) . $program . ' ' . $component . ': ' . $message;
     95        $syslog_message = '<22>' . date( 'M d H:i:s ' ) . $program . ' ' . $component . ': ' . $this->format( $message );
    8896
    8997        $sock = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
    9098        socket_sendto( $sock, $syslog_message, strlen( $syslog_message ), 0, $destination['hostname'], $destination['port'] );
    9199        socket_close( $sock );
     100
     101    }
     102
     103    public function format( $message ) {
     104
     105        if ( ! empty( $this->options['papertrail_enable_colorization'] ) && $this->options['papertrail_enable_colorization'] === 1 ) {
     106            $message = $this->colorise_json( $message );
     107        }
     108        return $message;
     109
     110    }
     111
     112    public function colorise_json( $json ) {
     113
     114        $seq = array(
     115            'reset' => "\033[0m",
     116            'color' => "\033[1;%dm",
     117            'bold'  => "\033[1m",
     118        );
     119
     120        $fcolor = array(
     121            'black'   => "\033[30m",
     122            'red'     => "\033[31m",
     123            'green'   => "\033[32m",
     124            'yellow'  => "\033[33m",
     125            'blue'    => "\033[34m",
     126            'magenta' => "\033[35m",
     127            'cyan'    => "\033[36m",
     128            'white'   => "\033[37m",
     129        );
     130
     131        $bcolor = array(
     132            'black'   => "\033[40m",
     133            'red'     => "\033[41m",
     134            'green'   => "\033[42m",
     135            'yellow'  => "\033[43m",
     136            'blue'    => "\033[44m",
     137            'magenta' => "\033[45m",
     138            'cyan'    => "\033[46m",
     139            'white'   => "\033[47m",
     140        );
     141
     142        $output = $json;
     143        $output = preg_replace( '/(":)([0-9]+)/', '$1' . $fcolor['magenta'] . '$2' . $seq['reset'], $output );
     144        $output = preg_replace( '/(":)(true|false)/', '$1' . $fcolor['magenta'] . '$2' . $seq['reset'], $output );
     145        $output = str_replace( '{"', '{' . $fcolor['green'] . '"', $output );
     146        $output = str_replace( ',"', ',' . $fcolor['green'] . '"', $output );
     147        $output = str_replace( '":', '"' . $seq['reset'] . ':', $output );
     148        $output = str_replace( ':"', ':' . $fcolor['green'] . '"', $output );
     149        $output = str_replace( '",', '"' . $seq['reset'] . ',', $output );
     150        $output = str_replace( '",', '"' . $seq['reset'] . ',', $output );
     151        $output = $seq['reset'] . $output . $seq['reset'];
     152
     153        return $output;
    92154
    93155    }
  • stream-to-papertrail/trunk/readme.txt

    r1239403 r1239660  
    44Requires at least:  4.3
    55Tested up to:       4.3
    6 Stable tag:         0.0.3
     6Stable tag:         0.0.4
    77License:            GPLv2 or later
    88License URI:        https://www.gnu.org/licenses/gpl-2.0.html
     
    2121
    2222== Changelog ==
     23
     24= 0.0.4 - September 7, 2015 =
     25
     26* Added option to enable/disable colourisation
     27
     28Props [@Japh](https://github.com/japh)
    2329
    2430= 0.0.3 - September 7, 2015 =
  • stream-to-papertrail/trunk/stream-papertrail.php

    r1239401 r1239660  
    55 * Description: Send Stream logs to Papertrail for safe-keeping.
    66 * Author: Japh
    7  * Version: 0.0.3
     7 * Version: 0.0.4
    88 * Author URI: http://japh.com.au/
    99 */
Note: See TracChangeset for help on using the changeset viewer.