| 12 | import org.jetbrains.annotations.Nullable; |
| 13 | |
| 14 | public class Procedure { |
| 15 | public static final long Success = 0; |
| 16 | public static final long Exception = -1; |
| 17 | public static final long TooManyTry = -2; |
| 18 | public static final long NotImplement = -3; |
| 19 | public static final long Unknown = -4; |
| 20 | public static final long ErrorSavepoint = -5; |
| 21 | public static final long LogicError = -6; |
| 22 | public static final long RedoAndRelease = -7; |
| 23 | public static final long AbortException = -8; |
| 24 | public static final long ProviderNotExist = -9; |
| 25 | public static final long Timeout = -10; |
| 26 | public static final long CancelException = -11; |
| 27 | public static final long DuplicateRequest = -12; |
| 28 | public static final long ErrorRequestId = -13; |
| 29 | public static final long ErrorSendFail = -14; |
| 30 | public static final long RaftRetry = -15; |
| 31 | public static final long RaftApplied = -16; |
| 32 | public static final long RaftExpired = -17; |
| 33 | public static final long Closed = -18; |
| 34 | public static final long Busy = -19; |
| 35 | public static final long AuthFail = -20; |
| 36 | // >0 用户自定义。 |
| 37 | |
| 38 | @FunctionalInterface |
| 39 | public interface ILogAction { |
| 40 | void run(@Nullable Throwable ex, long result, @NotNull Procedure p, @NotNull String message); |
| 41 | } |
| 42 | |
| 43 | private static final @NotNull Logger logger = LogManager.getLogger(Procedure.class); |
| 44 | public static final boolean ENABLE_DEBUG_LOG = logger.isDebugEnabled(); |
| 45 | public static final boolean ENABLE_TRACE_LOG = logger.isTraceEnabled(); |
| 46 | @SuppressWarnings("CanBeFinal") |
| 47 | public static @Nullable ILogAction logAction = Procedure::defaultLogAction; |
| 48 | |
| 49 | public static void defaultLogAction(@Nullable Throwable ex, long result, @NotNull Procedure p, |
| 50 | @NotNull String message) { |
| 51 | Level level; |
| 52 | if (ex != null) |
| 53 | level = Level.ERROR; |
| 54 | else if (result != 0) |
| 55 | level = p.zeze.getConfig().getProcessReturnErrorLogLevel(); |
| 56 | else if (ENABLE_TRACE_LOG) |
| 57 | level = Level.TRACE; |
| 58 | else |
| 59 | return; |
| 60 | |
| 61 | var moduleId = 0; |
| 62 | var errCode = result; |
| 63 | if (result > 0) { |
| 64 | moduleId = IModule.getModuleId(result); |
| 65 | errCode = IModule.getErrorCode(result); |
| 66 | } |
| 67 | if (null == ex) |
| 68 | logger.log(level, "Procedure={} Return={}:{} {}", p, moduleId, errCode, message); |
| 69 | else |
| 70 | logger.log(level, "Procedure={} Return={}:{} {}", p, moduleId, errCode, message, ex); |
| 71 | } |
nothing calls this directly
no outgoing calls
no test coverage detected