Last active
August 29, 2015 14:04
-
-
Save pcarrier/e7618f684b898fefbd6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
class Hello { | |
// Simple example (unknown field name, namespace "com/example/Hello", id "noop") | |
@Logged | |
native void noop(int a); | |
// Complex example (known field names, namespace "com/example", id "fooed") | |
@Logged(id="fooed", namespace="com/example", fields=["from", "to"]) | |
void foo(@LogFormat(As.HASHCODE) Bar source, @LogFormat(As.IDENTITY) Baz dest); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package java.lang.annotation; | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target({ElementType.PARAMETER}) | |
public @interface LogFormat { | |
As value; | |
public enum As { | |
STRING, // default, uses Object#toString() | |
HASHCODE, // uses Object#hashCode() | |
IDENTITY, // uses System.identityHashCode() | |
STRUCT, // uses recursive representation of public fields | |
IGNORED, // completely skipped | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package java.lang.annotation; | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target({ElementType.METHOD}) | |
public @interface Logged { | |
// defaults to method name, eg logMyEvent | |
String id() default null; | |
// defaults to class descriptor, eg com/example/Foo | |
String namespace() default null; | |
// name of each field; defaults to undefined | |
String[] fields[]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Supports primitive types & strings, LogFormat.As for other classes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment