<commit_before>use NativeCall;

class Log::Syslog::Native {
    enum LogLevel <Emergency Alert Critical Error Warning Notice Info Debug>;
    enum LogFacility (  :Kern( 0 +< 3),
                        :User( 1 +< 3),
                        :Mail( 2 +< 3),
                        :Daemon( 3 +< 3),
                        :Auth( 4 +< 3),
                        :Syslog( 5 +< 3),
                        :Lpr( 6 +< 3),
                        :News( 7 +< 3),
                        :Uucp( 8 +< 3),
                        :Cron( 9 +< 3),
                        :Authpriv( 10 +< 3),
                        :Ftp( 11 +< 3),
                        :Local0( 16 +< 3),
                        :Local1( 17 +< 3),
                        :Local2( 18 +< 3),
                        :Local3( 19 +< 3),
                        :Local4( 20 +< 3),
                        :Local5( 21 +< 3),
                        :Local6( 22 +< 3),
                        :Local7( 23 +< 3) );

    enum LogOptions (   :Pid(0x01), 
                        :Console(0x02), 
                        :ODelay(0x04), 
                        :NDelay(0x08),
                        :NoWait(0x10),
                        :Perror(0x20));

    has Str $.ident    = $*PROGRAM_NAME;
    has Int $.option   = Pid +| ODelay;
    has Int $.facility = Local0;

    sub _syslog(Int, Str) is native is symbol('syslog') { ... }
    sub _openlog(Str, Int, Int) is native is symbol('openlog') { ... }
    sub _closelog() is native is symbol('closelog') { ... }

    submethod BUILD(:$!ident, :$!option, :$!facility) {
        _openlog($!ident, $!option, $!facility);
    }

    method emergency(Str $format, *@args) {
        self.log(Emergency, $format, @args);
    }

    method alert(Str $format, *@args) {
        self.log(Alert, $format, @args);
    }
    
    method critical(Str $format, *@args) {
        self.log(Critical, $format, @args);
    }
    
    method error(Str $format, *@args) {
        self.log(Error, $format, @args);
    }
    
    method warnimg(Str $format, *@args) {
        self.log(Warning, $format, @args);
    }
    
    method notice(Str $format, *@args) {
        self.log(Notice, $format, @args);
    }

    method info(Str $format, *@args) {
        self.log(Info, $format, @args);
    }
    
    method debug(Str $format, *@args) {
        self.log(Info, $format, @args);
    }

    method log(LogLevel $priority, Str $format, *@args ) {
        my $mess = sprintf $format, @args;
        _syslog($priority.Int, $mess);

    }

    submethod DESTROY {
        _closelog();
    }
    <commit_msg>with temporary workaround for ident not working<commit_after>use NativeCall;

class Log::Syslog::Native {
    enum LogLevel <Emergency Alert Critical Error Warning Notice Info Debug>;
    enum LogFacility (  :Kern( 0 +< 3),
                        :User( 1 +< 3),
                        :Mail( 2 +< 3),
                        :Daemon( 3 +< 3),
                        :Auth( 4 +< 3),
                        :Syslog( 5 +< 3),
                        :Lpr( 6 +< 3),
                        :News( 7 +< 3),
                        :Uucp( 8 +< 3),
                        :Cron( 9 +< 3),
                        :Authpriv( 10 +< 3),
                        :Ftp( 11 +< 3),
                        :Local0( 16 +< 3),
                        :Local1( 17 +< 3),
                        :Local2( 18 +< 3),
                        :Local3( 19 +< 3),
                        :Local4( 20 +< 3),
                        :Local5( 21 +< 3),
                        :Local6( 22 +< 3),
                        :Local7( 23 +< 3) );

    enum LogOptions (   :Pid(0x01), 
                        :Console(0x02), 
                        :ODelay(0x04), 
                        :NDelay(0x08),
                        :NoWait(0x10),
                        :Perror(0x20));

    has Str $.ident    = $*PROGRAM_NAME;
    has Int $.option   = Pid +| ODelay;
    has Int $.facility = Local0;

    sub _syslog(Int, Str) is native is symbol('syslog') { ... }
    sub _openlog(Str, Int, Int) is native is symbol('openlog') { ... }
    sub _closelog() is native is symbol('closelog') { ... }

    submethod BUILD(:$!ident = $*PROGRAM_NAME, :$option?, :$facility) {
        $!option = $option // Pid +| ODelay;
        $!facility = $facility // Local0;
        _openlog(Str, $!option, $!facility);
    }

    method emergency(Str $format, *@args) {
        self.log(Emergency, $format, @args);
    }

    method alert(Str $format, *@args) {
        self.log(Alert, $format, @args);
    }
    
    method critical(Str $format, *@args) {
        self.log(Critical, $format, @args);
    }
    
    method error(Str $format, *@args) {
        self.log(Error, $format, @args);
    }
    
    method warnimg(Str $format, *@args) {
        self.log(Warning, $format, @args);
    }
    
    method notice(Str $format, *@args) {
        self.log(Notice, $format, @args);
    }

    method info(Str $format, *@args) {
        self.log(Info, $format, @args);
    }
    
    method debug(Str $format, *@args) {
        self.log(Info, $format, @args);
    }

    method log(LogLevel $priority, Str $format, *@args ) {
        my $mess = "[{ $!ident }] " ~ sprintf $format, @args;
        _syslog($priority.Int, $mess);

    }

    submethod DESTROY {
        _closelog();
    }
    
{'fraction_non_alphanumeric': 0.1524756189047262, 'fraction_numerical': 0.029069767441860465, 'mean_word_length': 1.3207136640557007, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1748386', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1665, 'n_words': 409}