mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 21:51:21 +00:00
Enable online logging manually in Logger::enable_online_logging() instead of BUILD() because threads don't share data.
This commit is contained in:
28
bin/pt-agent
28
bin/pt-agent
@@ -4843,8 +4843,17 @@ has '_thread' => (
|
||||
required => 0,
|
||||
);
|
||||
|
||||
sub BUILD {
|
||||
my $self = shift;
|
||||
has 'online_logging' => (
|
||||
is => 'rw',
|
||||
isa => 'Bool',
|
||||
required => 0,
|
||||
default => sub { return 0 },
|
||||
);
|
||||
|
||||
sub enable_online_logging {
|
||||
my ($self, %args) = @_;
|
||||
my $client = $args{client};
|
||||
my $log_link = $args{log_link};
|
||||
|
||||
$self->_message_queue(Thread::Queue->new());
|
||||
|
||||
@@ -4868,8 +4877,8 @@ sub BUILD {
|
||||
}
|
||||
if ( scalar @log_entries ) {
|
||||
eval {
|
||||
$self->client->post(
|
||||
link => $self->log_link,
|
||||
$client->post(
|
||||
link => $log_link,
|
||||
resources => \@log_entries,
|
||||
);
|
||||
};
|
||||
@@ -4885,6 +4894,8 @@ sub BUILD {
|
||||
} # threads::async
|
||||
);
|
||||
|
||||
$self->online_logging(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4951,7 +4962,7 @@ sub _log {
|
||||
else {
|
||||
print "$ts $level $msg\n";
|
||||
}
|
||||
if ( $self->client && $self->log_link ) {
|
||||
if ( $self->online_logging ) {
|
||||
my @event :shared = ($level_number, $msg);
|
||||
$self->_message_queue->enqueue(\@event);
|
||||
}
|
||||
@@ -5739,9 +5750,10 @@ These values can change if a different configuration is received.
|
||||
# simple info("Hello world!") to STDOUT won't block if the API isn't
|
||||
# responding. -- Both client and log_link are required to enable this.
|
||||
if ( $agent->links->{log} && $logger_client ) {
|
||||
$logger->client($logger_client);
|
||||
$logger->log_link($agent->links->{log});
|
||||
|
||||
$logger->enable_online_logging(
|
||||
client => $logger_client,
|
||||
log_link => $agent->links->{log},
|
||||
);
|
||||
$logger->info("Online logging enabled");
|
||||
}
|
||||
|
||||
|
@@ -72,8 +72,17 @@ has '_thread' => (
|
||||
required => 0,
|
||||
);
|
||||
|
||||
sub BUILD {
|
||||
my $self = shift;
|
||||
has 'online_logging' => (
|
||||
is => 'rw',
|
||||
isa => 'Bool',
|
||||
required => 0,
|
||||
default => sub { return 0 },
|
||||
);
|
||||
|
||||
sub enable_online_logging {
|
||||
my ($self, %args) = @_;
|
||||
my $client = $args{client};
|
||||
my $log_link = $args{log_link};
|
||||
|
||||
$self->_message_queue(Thread::Queue->new());
|
||||
|
||||
@@ -98,8 +107,8 @@ sub BUILD {
|
||||
}
|
||||
if ( scalar @log_entries ) {
|
||||
eval {
|
||||
$self->client->post(
|
||||
link => $self->log_link,
|
||||
$client->post(
|
||||
link => $log_link,
|
||||
resources => \@log_entries,
|
||||
);
|
||||
};
|
||||
@@ -115,6 +124,8 @@ sub BUILD {
|
||||
} # threads::async
|
||||
);
|
||||
|
||||
$self->online_logging(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -182,7 +193,7 @@ sub _log {
|
||||
else {
|
||||
print "$ts $level $msg\n";
|
||||
}
|
||||
if ( $self->client && $self->log_link ) {
|
||||
if ( $self->online_logging ) {
|
||||
my @event :shared = ($level_number, $msg);
|
||||
$self->_message_queue->enqueue(\@event);
|
||||
}
|
||||
|
Reference in New Issue
Block a user