or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

builder-pattern.mdconstructors.mddata-classes.mdexperimental.mdimmutable-patterns.mdindex.mdlogging.mdobject-methods.mdproperty-access.mdtype-inference.mdutilities.md

logging.mddocs/

0

# Logging

1

2

Seamless integration with popular Java logging frameworks through automatic logger field generation.

3

4

## Capabilities

5

6

### SLF4J Integration

7

8

```java { .api }

9

@Target(ElementType.TYPE)

10

@Retention(RetentionPolicy.SOURCE)

11

public @interface Slf4j {

12

String topic() default "";

13

}

14

15

@Target(ElementType.TYPE)

16

@Retention(RetentionPolicy.SOURCE)

17

public @interface XSlf4j {

18

String topic() default "";

19

}

20

```

21

22

### Log4j Integration

23

24

```java { .api }

25

@Target(ElementType.TYPE)

26

@Retention(RetentionPolicy.SOURCE)

27

public @interface Log4j {

28

String topic() default "";

29

}

30

31

@Target(ElementType.TYPE)

32

@Retention(RetentionPolicy.SOURCE)

33

public @interface Log4j2 {

34

String topic() default "";

35

}

36

```

37

38

### Other Logging Frameworks

39

40

```java { .api }

41

@Target(ElementType.TYPE)

42

@Retention(RetentionPolicy.SOURCE)

43

public @interface Log { // Java Util Logging

44

String topic() default "";

45

}

46

47

@Target(ElementType.TYPE)

48

@Retention(RetentionPolicy.SOURCE)

49

public @interface CommonsLog { // Apache Commons Logging

50

String topic() default "";

51

}

52

53

@Target(ElementType.TYPE)

54

@Retention(RetentionPolicy.SOURCE)

55

public @interface JBossLog { // JBoss Logging

56

String topic() default "";

57

}

58

59

@Target(ElementType.TYPE)

60

@Retention(RetentionPolicy.SOURCE)

61

public @interface Flogger { // Google Flogger

62

}

63

64

@Target(ElementType.TYPE)

65

@Retention(RetentionPolicy.SOURCE)

66

public @interface CustomLog {

67

String topic() default "";

68

}

69

```

70

71

**Usage Examples:**

72

73

```java

74

import lombok.extern.slf4j.Slf4j;

75

76

@Slf4j

77

public class UserService {

78

public void createUser(String name) {

79

log.info("Creating user: {}", name);

80

// Implementation

81

log.debug("User created successfully");

82

}

83

}

84

85

// Generated field:

86

// private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(UserService.class);

87

```

88

89

**Log4j2 Example:**

90

91

```java

92

import lombok.extern.log4j.Log4j2;

93

94

@Log4j2

95

public class PaymentProcessor {

96

public void processPayment(double amount) {

97

log.info("Processing payment of ${}", amount);

98

try {

99

// Payment processing logic

100

log.debug("Payment processed successfully");

101

} catch (Exception e) {

102

log.error("Payment processing failed", e);

103

}

104

}

105

}

106

107

// Generated field:

108

// private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(PaymentProcessor.class);

109

```

110

111

**Java Util Logging Example:**

112

113

```java

114

import lombok.extern.java.Log;

115

116

@Log

117

public class FileManager {

118

public void saveFile(String filename) {

119

log.info("Saving file: " + filename);

120

// Implementation

121

log.fine("File saved successfully");

122

}

123

}

124

125

// Generated field:

126

// private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(FileManager.class.getName());

127

```

128

129

**Custom Topic Example:**

130

131

```java

132

import lombok.extern.slf4j.Slf4j;

133

134

@Slf4j(topic = "AUDIT")

135

public class AuditService {

136

public void auditAction(String action) {

137

log.info("Audit: {}", action);

138

}

139

}

140

141

// Generated field:

142

// private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger("AUDIT");

143

```