blob: 48b376c38dcd848407a86b6953fd85594c93680c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// SPDX-FileCopyrightText: © 2024 Matthias Andreas Benkard <code@mail.matthias.benkard.de>
//
// SPDX-License-Identifier: LGPL-3.0-or-later
package eu.mulk.quarkus.googlecloud.jsonlogging;
import java.util.Objects;
import org.jspecify.annotations.Nullable;
/**
* A unique identifier for a log entry.
*
* <p>Prevents the duplicate insertion of log entries. Also serves as a discriminator to order log
* entries that carry the same time stamp.
*
* <p>Will be generated by Google Cloud Logging if not provided.
*
* <p>Instances of {@link InsertId} can be passed as log parameters to the {@code *f} family of
* logging functions on {@link org.jboss.logging.Logger}.
*
* <p><strong>Example:</strong>
*
* {@snippet :
* logger.logf("Request rejected: unauthorized.", InsertId.of("123"));
* }
*
* <p>Result:
*
* {@snippet lang="json" :
* {
* "textPayload": "Request rejected: unauthorized.",
* "logging.googleapis.com/insertId": "123"
* }
* }
*
* @see Label
* @see StructuredParameter
*/
public final class InsertId {
private final String value;
private InsertId(String value) {
this.value = value;
}
/**
* Constructs an {@link InsertId} from a string.
*
* @param value the value of the insertion ID.
* @return the newly constructed {@link InsertId}, ready to be passed to a logging function.
*/
public static InsertId of(String value) {
return new InsertId(value);
}
/**
* The value of the label.
*
* @return the value of the label.
*/
public String value() {
return value;
}
@Override
public boolean equals(@Nullable Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (InsertId) obj;
return Objects.equals(this.value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
return "InsertId[value=" + value + ']';
}
}
|