403Webshell
Server IP : 74.208.236.79  /  Your IP : 216.73.216.46
Web Server : Apache
System : Linux infongp-us50 4.4.400-icpu-108 #2 SMP Wed Feb 11 10:12:42 UTC 2026 x86_64
User : u93192080 ( 6162215)
PHP Version : 8.4.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/share/doc/liblog-log4perl-perl/examples/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/share/doc/liblog-log4perl-perl/examples//yamlparser
#!/usr/bin/perl
###########################################
# yamlparser
# Mike Schilli, 2004 (m@perlmeister.com)
###########################################
use warnings;
use strict;

package MyYAMLParser;
use base qw(Log::Log4perl::Config::BaseConfigurator);
use YAML qw(LoadFile Load);
use Data::Dumper;

###########################################
sub new {
###########################################
    my($class, %options) = @_;

    my $self = {};

    bless $self, $class;

    $self->{text} = $options{text} if exists $options{text};
    $self->{file} = $options{file} if exists $options{file};

    if(! exists $self->{text} and 
       ! exists $self->{file}) {
        die "usage: ", __PACKAGE__, "->new(file => \$filename) or ",
                       __PACKAGE__, "->new(text => \$text)";
    }

    return $self;
}

###########################################
sub parse {
###########################################
    my($self) = @_;    

    my $data = {};

    if(exists $self->{text}) {
        $self->{data} = Load($self->{text});
    }

    # Move all non-hash values under {...}->{value}
    my @todo = ($self->{data});

    while (@todo) {
        my $ref = shift @todo;
        for (keys %$ref) {
            if(ref($ref->{$_}) eq "HASH") {
                push @todo, $ref->{$_};
            } elsif($_ eq "name") {
                   # Appender 'name' entries are 
                   # converted to ->{value} entries
                $ref->{value} = $ref->{$_};
                delete $ref->{$_};
            } else {
                my $tmp = $ref->{$_};
                $ref->{$_} = {};
                $ref->{$_}->{value} = $tmp;
            }
        }
    }

    return $self->{data};
}

package main;

use Log::Log4perl;

my $p = MyYAMLParser->new(text => <<EOT);
  category:
        Bar:
          Twix: WARN, Screen, Screen2
  appender:
        Screen: 
            name:   Log::Log4perl::Appender::Screen
            layout: Log::Log4perl::Layout::SimpleLayout
        Screen2: 
            name:   Log::Log4perl::Appender::Screen
            layout: Log::Log4perl::Layout::SimpleLayout
EOT

# use Data::Dump qw(dump);
# print dump($p->parse());

Log::Log4perl->init($p);

my $log = Log::Log4perl->get_logger("Bar::Twix");
$log->warn('foo');

Youez - 2016 - github.com/yon3zu
LinuXploit