aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-05-27 18:46:12 +0200
committerPatrick Spek <p.spek@tyil.nl>2020-05-27 18:46:12 +0200
commit5142e4af22df9b4df3b3f0bf122b1134ebf9c9d2 (patch)
treec8b9097856ba5deaed92a6108198ed211c32ac6d
parentadd1f04be6df5a61c8c30a405b3aa857d9e01ea6 (diff)
downloadLog::JSON-5142e4af22df9b4df3b3f0bf122b1134ebf9c9d2.tar.gz
Log::JSON-5142e4af22df9b4df3b3f0bf122b1134ebf9c9d2.tar.bz2
Add optional metadata to log calls
-rw-r--r--lib/Log/JSON.rakumod90
1 files changed, 71 insertions, 19 deletions
diff --git a/lib/Log/JSON.rakumod b/lib/Log/JSON.rakumod
index 344af57..a90fc1e 100644
--- a/lib/Log/JSON.rakumod
+++ b/lib/Log/JSON.rakumod
@@ -24,9 +24,12 @@ has Bool:D $.pretty = False;
multi method emergency (
#| The message to print.
Str:D $message,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('emergency', $message),
+ message => self!message('emergency', $message, |%meta),
level => 0,
})
}
@@ -38,9 +41,12 @@ multi method emergency (
#| Arguments to substitute into the format string placeholders.
*@args,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('emergency', $format.sprintf(|@args)),
+ message => self!message('emergency', $format.sprintf(|@args), |%meta),
level => 0,
})
}
@@ -49,9 +55,12 @@ multi method emergency (
multi method alert (
#| The message to print.
Str:D $message,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('alert', $message),
+ message => self!message('alert', $message, |%meta),
level => 1,
})
}
@@ -63,9 +72,12 @@ multi method alert (
#| Arguments to substitute into the format string placeholders.
*@args,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('alert', $format.sprintf(|@args)),
+ message => self!message('alert', $format.sprintf(|@args), |%meta),
level => 1,
})
}
@@ -74,9 +86,12 @@ multi method alert (
multi method critical (
#| The message to print.
Str:D $message,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('critical', $message),
+ message => self!message('critical', $message, |%meta),
level => 2,
})
}
@@ -88,9 +103,12 @@ multi method critical (
#| Arguments to substitute into the format string placeholders.
*@args,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('critical', $format.sprintf(|@args)),
+ message => self!message('critical', $format.sprintf(|@args), |%meta),
level => 2,
})
}
@@ -99,9 +117,12 @@ multi method critical (
multi method error (
#| The message to print.
Str:D $message,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('error', $message),
+ message => self!message('error', $message, |%meta),
level => 3,
})
}
@@ -113,9 +134,12 @@ multi method error (
#| Arguments to substitute into the format string placeholders.
*@args,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('error', $format.sprintf(|@args)),
+ message => self!message('error', $format.sprintf(|@args), |%meta),
level => 3,
})
}
@@ -124,9 +148,12 @@ multi method error (
multi method warning (
#| The message to print.
Str:D $message,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('warning', $message),
+ message => self!message('warning', $message, |%meta),
level => 4,
})
}
@@ -138,9 +165,12 @@ multi method warning (
#| Arguments to substitute into the format string placeholders.
*@args,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('warning', $format.sprintf(|@args)),
+ message => self!message('warning', $format.sprintf(|@args), |%meta),
level => 4,
})
}
@@ -148,10 +178,13 @@ multi method warning (
#| Send a notice message. This is the "normal" level to publish log entries on.
multi method notice (
#| The message to print.
- Str:D $message
+ Str:D $message,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('notice', $message),
+ message => self!message('notice', $message, |%meta),
level => 5,
})
}
@@ -164,9 +197,12 @@ multi method notice (
#| Arguments to substitute into the format string placeholders.
*@args,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('notice', $format.sprintf(|@args)),
+ message => self!message('notice', $format.sprintf(|@args), |%meta),
level => 5,
})
}
@@ -174,10 +210,13 @@ multi method notice (
#| Send an informational message.
multi method info (
#| The message to print.
- Str:D $message
+ Str:D $message,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('info', $message),
+ message => self!message('info', $message, |%meta),
level => 6,
})
}
@@ -189,9 +228,12 @@ multi method info (
#| Arguments to substitute into the format string placeholders.
*@args,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('info', $format.sprintf(|@args)),
+ message => self!message('info', $format.sprintf(|@args), |%meta),
level => 6,
})
}
@@ -200,9 +242,12 @@ multi method info (
multi method debug (
#| The message to print.
Str:D $message,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('debug', $message),
+ message => self!message('debug', $message, |%meta),
level => 7,
})
}
@@ -214,9 +259,12 @@ multi method debug (
#| Arguments to substitute into the format string placeholders.
*@args,
+
+ #| Any additional fields of metadata to include.
+ *%meta,
) {
$!messages.emit({
- message => self!message('debug', $format.sprintf(|@args)),
+ message => self!message('debug', $format.sprintf(|@args), |%meta),
level => 7,
})
}
@@ -262,6 +310,9 @@ method !message (
#| The original message to be logged.
Str:D $message,
+ #| Any additional fields for metadata on the log message.
+ *%meta,
+
--> Str
) {
to-json({
@@ -269,7 +320,8 @@ method !message (
hostname => $*KERNEL.hostname,
origin => self!callee,
:$level,
- :$message
+ :$message,
+ |%meta,
}, :$!pretty);
}