+ $contexts->{$_} = 1;
+ }
+ foreach my $log_email (
+ qsearch('log_email',
+ {
+ 'disabled' => '',
+ 'min_level' => {
+ 'op' => '<=',
+ 'value' => $self->level,
+ },
+ }
+ )
+ ) {
+ # shouldn't be a lot of these, so not packing this into the qsearch
+ next if $log_email->context && !$contexts->{$log_email->context};
+ my $msg_template = qsearchs('msg_template',{ 'msgnum' => $log_email->msgnum });
+ unless ($msg_template) {
+ warn "Could not send email when logging, could not load message template for logemailnum " . $log_email->logemailnum;
+ next;
+ }
+ my $emailerror = $msg_template->send(
+ 'to' => $log_email->to_addr,
+ 'substitutions' => {
+ 'loglevel' => $FS::Log::LEVELS[$self->level], # which has hopefully been loaded...
+ 'logcontext' => $log_email->context, # use the one that triggered the email
+ 'logmessage' => $self->message,
+ },
+ );
+ warn "Could not send email when logging: $emailerror" if $emailerror;