summaryrefslogtreecommitdiffstats
path: root/extensions/PhabBugz/lib/Logger.pm
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/PhabBugz/lib/Logger.pm')
-rw-r--r--extensions/PhabBugz/lib/Logger.pm37
1 files changed, 37 insertions, 0 deletions
diff --git a/extensions/PhabBugz/lib/Logger.pm b/extensions/PhabBugz/lib/Logger.pm
new file mode 100644
index 000000000..3127b66db
--- /dev/null
+++ b/extensions/PhabBugz/lib/Logger.pm
@@ -0,0 +1,37 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Extension::PhabBugz::Logger;
+
+use 5.10.1;
+
+use Moo;
+
+use Bugzilla::Extension::PhabBugz::Constants;
+
+has 'debugging' => ( is => 'ro' );
+
+sub info { shift->_log_it('INFO', @_) }
+sub error { shift->_log_it('ERROR', @_) }
+sub debug { shift->_log_it('DEBUG', @_) }
+
+sub _log_it {
+ my ($self, $method, $message) = @_;
+
+ return if $method eq 'DEBUG' && !$self->debugging;
+ chomp $message;
+ if ($ENV{MOD_PERL}) {
+ require Apache2::Log;
+ Apache2::ServerRec::warn("FEED $method: $message");
+ } elsif ($ENV{SCRIPT_FILENAME}) {
+ print STDERR "FEED $method: $message\n";
+ } else {
+ print STDERR '[' . localtime(time) ."] $method: $message\n";
+ }
+}
+
+1;