| 1 | package Zing::Journal; | ||
| 2 | |||
| 3 | use 5.014; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use registry 'Zing::Types'; | ||
| 9 | use routines; | ||
| 10 | |||
| 11 | use Data::Object::Class; | ||
| 12 | use Data::Object::ClassHas; | ||
| 13 | |||
| 14 | extends 'Zing::Channel'; | ||
| 15 | |||
| 16 | our $VERSION = '0.26'; # VERSION | ||
| 17 | |||
| 18 | # ATTRIBUTES | ||
| 19 | |||
| 20 | has 'name' => ( | ||
| 21 | is => 'ro', | ||
| 22 | isa => 'Str', | ||
| 23 | init_arg => undef, | ||
| 24 | new => 1, | ||
| 25 | mod => 1, | ||
| 26 | ); | ||
| 27 | |||
| 28 | fun new_name($self) { | ||
| 29 | '$journal' | ||
| 30 | } | ||
| 31 | |||
| 32 | has level => ( | ||
| 33 | is => 'ro', | ||
| 34 | isa => 'Str', | ||
| 35 | def => 'debug', | ||
| 36 | ); | ||
| 37 | |||
| 38 | has tap => ( | ||
| 39 | is => 'rw', | ||
| 40 | isa => 'Bool', | ||
| 41 | def => 1, | ||
| 42 | ); | ||
| 43 | |||
| 44 | has verbose => ( | ||
| 45 | is => 'ro', | ||
| 46 | isa => 'Bool', | ||
| 47 | def => 0, | ||
| 48 | ); | ||
| 49 | |||
| 50 | # METHODS | ||
| 51 | |||
| 52 | method stream(CodeRef $callback) { | ||
| 53 | while ($self->tap) { | ||
| 54 | next unless my $info = $self->recv; | ||
| 55 | |||
| 56 | my $from = $info->{from}; | ||
| 57 | my $data = $info->{data}; | ||
| 58 | my $logs = $data->{logs}; | ||
| 59 | |||
| 60 | $logs->{level} = $self->level; | ||
| 61 | |||
| 62 | my $logger = $self->app->logger(%{$logs}); | ||
| 63 | my $report = $self->verbose ? 'verbose' : 'simple'; | ||
| 64 | my $lines = $logger->$report->lines; | ||
| 65 | |||
| 66 | $callback->($info, $data, $lines); | ||
| 67 | } | ||
| 68 | |||
| 69 | return $self; | ||
| 70 | } | ||
| 71 | |||
| 72 | 1; | ||
| 73 | |||
| 74 | =encoding utf8 | ||
| 75 | |||
| 76 | =head1 NAME | ||
| 77 | |||
| 78 | Zing::Journal - System Journal | ||
| 79 | |||
| 80 | =cut | ||
| 81 | |||
| 82 | =head1 ABSTRACT | ||
| 83 | |||
| 84 | Central System Journal | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | =head1 SYNOPSIS | ||
| 89 | |||
| 90 | use Zing::Journal; | ||
| 91 | |||
| 92 | my $journal = Zing::Journal->new; | ||
| 93 | |||
| 94 | # $journal->recv; | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | =head1 DESCRIPTION | ||
| 99 | |||
| 100 | This package provides the default central mechanism for creating and retrieving | ||
| 101 | process event logs. | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | =head1 INHERITS | ||
| 106 | |||
| 107 | This package inherits behaviors from: | ||
| 108 | |||
| 109 | L<Zing::Channel> | ||
| 110 | |||
| 111 | =cut | ||
| 112 | |||
| 113 | =head1 LIBRARIES | ||
| 114 | |||
| 115 | This package uses type constraints from: | ||
| 116 | |||
| 117 | L<Zing::Types> | ||
| 118 | |||
| 119 | =cut | ||
| 120 | |||
| 121 | =head1 ATTRIBUTES | ||
| 122 | |||
| 123 | This package has the following attributes: | ||
| 124 | |||
| 125 | =cut | ||
| 126 | |||
| 127 | =head2 level | ||
| 128 | |||
| 129 | level(Str) | ||
| 130 | |||
| 131 | This attribute is read-only, accepts C<(Str)> values, and is optional. | ||
| 132 | |||
| 133 | =cut | ||
| 134 | |||
| 135 | =head2 name | ||
| 136 | |||
| 137 | name(Str) | ||
| 138 | |||
| 139 | This attribute is read-only, accepts C<(Str)> values, and is optional. | ||
| 140 | |||
| 141 | =cut | ||
| 142 | |||
| 143 | =head2 tap | ||
| 144 | |||
| 145 | tap(Bool) | ||
| 146 | |||
| 147 | This attribute is read-write, accepts C<(Bool)> values, and is optional. | ||
| 148 | |||
| 149 | =cut | ||
| 150 | |||
| 151 | =head2 verbose | ||
| 152 | |||
| 153 | verbose(Bool) | ||
| 154 | |||
| 155 | This attribute is read-only, accepts C<(Bool)> values, and is optional. | ||
| 156 | |||
| 157 | =cut | ||
| 158 | |||
| 159 | =head1 METHODS | ||
| 160 | |||
| 161 | This package implements the following methods: | ||
| 162 | |||
| 163 | =cut | ||
| 164 | |||
| 165 | =head2 stream | ||
| 166 | |||
| 167 | stream(CodeRef $callback) : Object | ||
| 168 | |||
| 169 | The stream method taps the process event log and executes the provided callback | ||
| 170 | for each new event. | ||
| 171 | |||
| 172 | =over 4 | ||
| 173 | |||
| 174 | =item stream example #1 | ||
| 175 | |||
| 176 | # given: synopsis | ||
| 177 | |||
| 178 | my $example = { | ||
| 179 | from => '...', | ||
| 180 | data => {logs => {}}, | ||
| 181 | }; | ||
| 182 | |||
| 183 | for (1..5) { | ||
| 184 | $journal->send($example); | ||
| 185 | } | ||
| 186 | |||
| 187 | $journal->stream(sub { | ||
| 188 | my ($info, $data, $lines) = @_; | ||
| 189 | $journal->tap(0); # stop | ||
| 190 | }); | ||
| 191 | |||
| 192 | =back | ||
| 193 | |||
| 194 | =cut | ||
| 195 | |||
| 196 | =head2 term | ||
| 197 | |||
| 198 | term() : Str | ||
| 199 | |||
| 200 | The term method returns the name of the journal. | ||
| 201 | |||
| 202 | =over 4 | ||
| 203 | |||
| 204 | =item term example #1 | ||
| 205 | |||
| 206 | # given: synopsis | ||
| 207 | |||
| 208 | $journal->term; | ||
| 209 | |||
| 210 | =back | ||
| 211 | |||
| 212 | =cut | ||
| 213 | |||
| 214 | =head1 AUTHOR | ||
| 215 | |||
| 216 | Al Newkirk, C<awncorp@cpan.org> | ||
| 217 | |||
| 218 | =head1 LICENSE | ||
| 219 | |||
| 220 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 221 | |||
| 222 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 223 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 224 | file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>. | ||
| 225 | |||
| 226 | =head1 PROJECT | ||
| 227 | |||
| 228 | L<Wiki|https://github.com/iamalnewkirk/zing/wiki> | ||
| 229 | |||
| 230 | L<Project|https://github.com/iamalnewkirk/zing> | ||
| 231 | |||
| 232 | L<Initiatives|https://github.com/iamalnewkirk/zing/projects> | ||
| 233 | |||
| 234 | L<Milestones|https://github.com/iamalnewkirk/zing/milestones> | ||
| 235 | |||
| 236 | L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md> | ||
| 237 | |||
| 238 | L<Issues|https://github.com/iamalnewkirk/zing/issues> | ||
| 239 | |||
| 240 | =cut |