Skip to content

Commit c95a6c1

Browse files
committed
Merge branch 'logger-access'
2 parents de829d1 + 71d85ca commit c95a6c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1199
-48
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ John Paul Taylor II <[email protected]>
2626
Karthik kathari <[email protected]>
2727
Kevin Chirls <[email protected]>
2828
Liu DongMiao <[email protected]>
29+
Liam Pace <[email protected]>
2930
Luan Nico <[email protected]>
3031
Maarten Mulders <[email protected]>
3132
Manu Sridharan <[email protected]>

doc/changelog.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Lombok Changelog
22
----------------
33

44
### v1.18.41 "Edgy Guinea Pig"
5+
* FEATURE: All the various `@Log` annotations now allow you to change their access level (they still default to `private`). [#2280](https://github.com/projectlombok/lombok/issues/2280). Thanks to new contributor Liam Pace!
56
* BUGFIX: Javadoc parsing was broken in Netbeans and ErrorProne for JDK25 [#3940](https://github.com/projectlombok/lombok/issues/3940).
67

78
### v1.18.40 (September 4th, 2025)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build/
2+
.gradle/
3+
gradle/
4+
gradlew
5+
gradlew.bat

src/core/lombok/AccessLevel.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009 The Project Lombok Authors.
2+
* Copyright (C) 2009-2025 The Project Lombok Authors.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -25,7 +25,24 @@
2525
* Represents an AccessLevel. Used e.g. to specify the access level for generated methods and fields.
2626
*/
2727
public enum AccessLevel {
28-
PUBLIC, MODULE, PROTECTED, PACKAGE, PRIVATE,
28+
/** Represents the {@code public} access level. */
29+
PUBLIC,
30+
31+
/**
32+
* Acts exactly like {@code PACKAGE} - the package private access level.
33+
* @deprecated This value was created at a time when a module-level access keyword was planned as a way of being prepared for the future. But that's not the direction java went in; a 'module access level' is not likely to ever exist. This enum acts like {@code PACKAGE} in every way.
34+
*/
35+
@Deprecated MODULE,
36+
37+
/** Represents the {@code protected} access level (any code in the same package as well as any subtype). */
38+
PROTECTED,
39+
40+
/** Represents the default access level: package private. (any code in the same package). */
41+
PACKAGE,
42+
43+
/** Represents the {@code private} access level. */
44+
PRIVATE,
45+
2946
/** Represents not generating anything or the complete lack of a method. */
3047
NONE;
3148
}

src/core/lombok/CustomLog.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
@Retention(RetentionPolicy.SOURCE)
6666
@Target(ElementType.TYPE)
6767
public @interface CustomLog {
68+
/**
69+
* Sets the access level of the generated log field.
70+
* Default: {@code AccessLevel.PRIVATE}.
71+
*
72+
* @return The constructed Logger method will be generated with this access modifier.
73+
*/
74+
AccessLevel access() default AccessLevel.PRIVATE;
75+
6876
/**
6977
*
7078
* Sets a custom topic/category. Note that this requires you to specify a parameter configuration for your custom logger that includes {@code TOPIC}.

src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,7 @@ public static TypeReference makeType(TypeBinding binding, ASTNode pos, boolean a
13931393
/**
13941394
* Turns an {@code AccessLevel} instance into the flag bit used by eclipse.
13951395
*/
1396+
@SuppressWarnings("deprecation") // We have to use MODULE here to make it act according to spec, which is to treat it like `PACKAGE`.
13961397
public static int toEclipseModifier(AccessLevel value) {
13971398
switch (value) {
13981399
case MODULE:

src/core/lombok/eclipse/handlers/HandleLog.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2010-2024 The Project Lombok Authors.
2+
* Copyright (C) 2010-2025 The Project Lombok Authors.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -39,6 +39,7 @@
3939
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
4040
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
4141

42+
import lombok.AccessLevel;
4243
import lombok.ConfigurationKeys;
4344
import lombok.core.AnnotationValues;
4445
import lombok.core.configuration.IdentifierName;
@@ -57,7 +58,7 @@ private HandleLog() {
5758
throw new UnsupportedOperationException();
5859
}
5960

60-
public static void processAnnotation(LoggingFramework framework, AnnotationValues<? extends java.lang.annotation.Annotation> annotation, Annotation source, EclipseNode annotationNode) {
61+
public static void processAnnotation(LoggingFramework framework, AccessLevel access, AnnotationValues<? extends java.lang.annotation.Annotation> annotation, Annotation source, EclipseNode annotationNode) {
6162
EclipseNode owner = annotationNode.up();
6263

6364
switch (owner.getKind()) {
@@ -97,6 +98,7 @@ public static void processAnnotation(LoggingFramework framework, AnnotationValue
9798
Expression loggerTopic = (Expression) annotation.getActualExpression("topic");
9899

99100
if (valueGuess instanceof String && ((String) valueGuess).trim().isEmpty()) loggerTopic = null;
101+
100102
if (framework.getDeclaration().getParametersWithTopic() == null && loggerTopic != null) {
101103
annotationNode.addError(framework.getAnnotationAsString() + " does not allow a topic.");
102104
loggerTopic = null;
@@ -106,8 +108,10 @@ public static void processAnnotation(LoggingFramework framework, AnnotationValue
106108
loggerTopic = new StringLiteral(new char[]{}, 0, 0, 0);
107109
}
108110

111+
if (access == AccessLevel.NONE) break;
112+
109113
ClassLiteralAccess loggingType = selfType(owner, source);
110-
FieldDeclaration fieldDeclaration = createField(framework, source, loggingType, logFieldName.getName(), useStatic, loggerTopic);
114+
FieldDeclaration fieldDeclaration = createField(framework, access, source, loggingType, logFieldName.getName(), useStatic, loggerTopic);
111115
fieldDeclaration.traverse(new SetGeneratedByVisitor(source), typeDecl.staticInitializerScope);
112116
injectFieldAndMarkGenerated(owner, fieldDeclaration);
113117
owner.rebuild();
@@ -131,15 +135,15 @@ public static ClassLiteralAccess selfType(EclipseNode type, Annotation source) {
131135
return result;
132136
}
133137

134-
private static FieldDeclaration createField(LoggingFramework framework, Annotation source, ClassLiteralAccess loggingType, String logFieldName, boolean useStatic, Expression loggerTopic) {
138+
private static FieldDeclaration createField(LoggingFramework framework, AccessLevel access, Annotation source, ClassLiteralAccess loggingType, String logFieldName, boolean useStatic, Expression loggerTopic) {
135139
int pS = source.sourceStart, pE = source.sourceEnd;
136140
long p = (long) pS << 32 | pE;
137141

138142
// private static final <loggerType> log = <factoryMethod>(<parameter>);
139143
FieldDeclaration fieldDecl = new FieldDeclaration(logFieldName.toCharArray(), 0, -1);
140144
setGeneratedBy(fieldDecl, source);
141145
fieldDecl.declarationSourceEnd = -1;
142-
fieldDecl.modifiers = Modifier.PRIVATE | (useStatic ? Modifier.STATIC : 0) | Modifier.FINAL;
146+
fieldDecl.modifiers = toEclipseModifier(access) | (useStatic ? Modifier.STATIC : 0) | Modifier.FINAL;
143147

144148
LogDeclaration logDeclaration = framework.getDeclaration();
145149
fieldDecl.type = createTypeReference(logDeclaration.getLoggerType().getName(), source);
@@ -215,7 +219,7 @@ private static final Expression createFactoryTypeParameter(ClassLiteralAccess lo
215219
public static class HandleCommonsLog extends EclipseAnnotationHandler<lombok.extern.apachecommons.CommonsLog> {
216220
@Override public void handle(AnnotationValues<lombok.extern.apachecommons.CommonsLog> annotation, Annotation source, EclipseNode annotationNode) {
217221
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_COMMONS_FLAG_USAGE, "@apachecommons.CommonsLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
218-
processAnnotation(LoggingFramework.COMMONS, annotation, source, annotationNode);
222+
processAnnotation(LoggingFramework.COMMONS, annotation.getInstance().access(), annotation, source, annotationNode);
219223
}
220224
}
221225

@@ -226,7 +230,7 @@ public static class HandleCommonsLog extends EclipseAnnotationHandler<lombok.ext
226230
public static class HandleJulLog extends EclipseAnnotationHandler<lombok.extern.java.Log> {
227231
@Override public void handle(AnnotationValues<lombok.extern.java.Log> annotation, Annotation source, EclipseNode annotationNode) {
228232
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_JUL_FLAG_USAGE, "@java.Log", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
229-
processAnnotation(LoggingFramework.JUL, annotation, source, annotationNode);
233+
processAnnotation(LoggingFramework.JUL, annotation.getInstance().access(), annotation, source, annotationNode);
230234
}
231235
}
232236

@@ -237,7 +241,7 @@ public static class HandleJulLog extends EclipseAnnotationHandler<lombok.extern.
237241
public static class HandleLog4jLog extends EclipseAnnotationHandler<lombok.extern.log4j.Log4j> {
238242
@Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j> annotation, Annotation source, EclipseNode annotationNode) {
239243
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_LOG4J_FLAG_USAGE, "@Log4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
240-
processAnnotation(LoggingFramework.LOG4J, annotation, source, annotationNode);
244+
processAnnotation(LoggingFramework.LOG4J, annotation.getInstance().access(), annotation, source, annotationNode);
241245
}
242246
}
243247

@@ -248,7 +252,7 @@ public static class HandleLog4jLog extends EclipseAnnotationHandler<lombok.exter
248252
public static class HandleLog4j2Log extends EclipseAnnotationHandler<lombok.extern.log4j.Log4j2> {
249253
@Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j2> annotation, Annotation source, EclipseNode annotationNode) {
250254
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_LOG4J2_FLAG_USAGE, "@Log4j2", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
251-
processAnnotation(LoggingFramework.LOG4J2, annotation, source, annotationNode);
255+
processAnnotation(LoggingFramework.LOG4J2, annotation.getInstance().access(), annotation, source, annotationNode);
252256
}
253257
}
254258

@@ -259,7 +263,7 @@ public static class HandleLog4j2Log extends EclipseAnnotationHandler<lombok.exte
259263
public static class HandleSlf4jLog extends EclipseAnnotationHandler<lombok.extern.slf4j.Slf4j> {
260264
@Override public void handle(AnnotationValues<lombok.extern.slf4j.Slf4j> annotation, Annotation source, EclipseNode annotationNode) {
261265
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_SLF4J_FLAG_USAGE, "@Slf4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
262-
processAnnotation(LoggingFramework.SLF4J, annotation, source, annotationNode);
266+
processAnnotation(LoggingFramework.SLF4J, annotation.getInstance().access(), annotation, source, annotationNode);
263267
}
264268
}
265269

@@ -270,7 +274,7 @@ public static class HandleSlf4jLog extends EclipseAnnotationHandler<lombok.exter
270274
public static class HandleXSlf4jLog extends EclipseAnnotationHandler<lombok.extern.slf4j.XSlf4j> {
271275
@Override public void handle(AnnotationValues<lombok.extern.slf4j.XSlf4j> annotation, Annotation source, EclipseNode annotationNode) {
272276
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_XSLF4J_FLAG_USAGE, "@XSlf4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
273-
processAnnotation(LoggingFramework.XSLF4J, annotation, source, annotationNode);
277+
processAnnotation(LoggingFramework.XSLF4J, annotation.getInstance().access(), annotation, source, annotationNode);
274278
}
275279
}
276280

@@ -281,7 +285,7 @@ public static class HandleXSlf4jLog extends EclipseAnnotationHandler<lombok.exte
281285
public static class HandleJBossLog extends EclipseAnnotationHandler<lombok.extern.jbosslog.JBossLog> {
282286
@Override public void handle(AnnotationValues<lombok.extern.jbosslog.JBossLog> annotation, Annotation source, EclipseNode annotationNode) {
283287
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_JBOSSLOG_FLAG_USAGE, "@JBossLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
284-
processAnnotation(LoggingFramework.JBOSSLOG, annotation, source, annotationNode);
288+
processAnnotation(LoggingFramework.JBOSSLOG, annotation.getInstance().access(), annotation, source, annotationNode);
285289
}
286290
}
287291

@@ -292,7 +296,7 @@ public static class HandleJBossLog extends EclipseAnnotationHandler<lombok.exter
292296
public static class HandleFloggerLog extends EclipseAnnotationHandler<lombok.extern.flogger.Flogger> {
293297
@Override public void handle(AnnotationValues<lombok.extern.flogger.Flogger> annotation, Annotation source, EclipseNode annotationNode) {
294298
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_FLOGGER_FLAG_USAGE, "@Flogger", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
295-
processAnnotation(LoggingFramework.FLOGGER, annotation, source, annotationNode);
299+
processAnnotation(LoggingFramework.FLOGGER, annotation.getInstance().access(), annotation, source, annotationNode);
296300
}
297301
}
298302

@@ -309,7 +313,7 @@ public static class HandleCustomLog extends EclipseAnnotationHandler<lombok.Cust
309313
return;
310314
}
311315
LoggingFramework framework = new LoggingFramework(lombok.CustomLog.class, logDeclaration);
312-
processAnnotation(framework, annotation, source, annotationNode);
316+
processAnnotation(framework, annotation.getInstance().access(), annotation, source, annotationNode);
313317
}
314318
}
315319
}

src/core/lombok/extern/apachecommons/CommonsLog.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2010-2017 The Project Lombok Authors.
2+
* Copyright (C) 2010-2025 The Project Lombok Authors.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,8 @@
2626
import java.lang.annotation.RetentionPolicy;
2727
import java.lang.annotation.Target;
2828

29+
import lombok.AccessLevel;
30+
2931
/**
3032
* Causes lombok to generate a logger field.
3133
* <p>
@@ -62,6 +64,14 @@
6264
@Retention(RetentionPolicy.SOURCE)
6365
@Target(ElementType.TYPE)
6466
public @interface CommonsLog {
67+
/**
68+
* Sets the access level of the generated log field.
69+
* Default: {@code AccessLevel.PRIVATE}.
70+
*
71+
* @return The constructed Logger method will be generated with this access modifier.
72+
*/
73+
AccessLevel access() default AccessLevel.PRIVATE;
74+
6575
/** @return The category of the constructed Logger. By default, it will use the type where the annotation is placed. */
6676
String topic() default "";
6777
}

src/core/lombok/extern/flogger/Flogger.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018 The Project Lombok Authors.
2+
* Copyright (C) 2018-2025 The Project Lombok Authors.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,8 @@
2626
import java.lang.annotation.RetentionPolicy;
2727
import java.lang.annotation.Target;
2828

29+
import lombok.AccessLevel;
30+
2931
/**
3032
* Causes lombok to generate a logger field.
3133
* <p>
@@ -60,4 +62,11 @@
6062
@Retention(RetentionPolicy.SOURCE)
6163
@Target(ElementType.TYPE)
6264
public @interface Flogger {
65+
/**
66+
* Sets the access level of the generated log field.
67+
* Default: {@code AccessLevel.PRIVATE}.
68+
*
69+
* @return The constructed Logger method will be generated with this access modifier.
70+
*/
71+
AccessLevel access() default AccessLevel.PRIVATE;
6372
}

src/core/lombok/extern/java/Log.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2010-2017 The Project Lombok Authors.
2+
* Copyright (C) 2010-2025 The Project Lombok Authors.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,8 @@
2626
import java.lang.annotation.RetentionPolicy;
2727
import java.lang.annotation.Target;
2828

29+
import lombok.AccessLevel;
30+
2931
/**
3032
* Causes lombok to generate a logger field.
3133
* <p>
@@ -61,6 +63,14 @@
6163
@Retention(RetentionPolicy.SOURCE)
6264
@Target(ElementType.TYPE)
6365
public @interface Log {
66+
/**
67+
* Sets the access level of the generated log field.
68+
* Default: {@code AccessLevel.PRIVATE}.
69+
*
70+
* @return The constructed Logger method will be generated with this access modifier.
71+
*/
72+
AccessLevel access() default AccessLevel.PRIVATE;
73+
6474
/** @return The category of the constructed Logger. By default, it will use the type where the annotation is placed. */
6575
String topic() default "";
6676
}

0 commit comments

Comments
 (0)