|
| 1 | +/* |
| 2 | + * Copyright 2023 NAVER Corp. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | +package com.navercorp.pinpoint.bootstrap.java9.module; |
| 19 | + |
| 20 | +/** |
| 21 | + * @author yjqg6666 |
| 22 | + */ |
| 23 | +enum ModuleLogLevel { |
| 24 | + |
| 25 | + ERROR(40), |
| 26 | + WARN(30), |
| 27 | + INFO(20), |
| 28 | + DEBUG(10), |
| 29 | + TRACE(0); |
| 30 | + |
| 31 | + private final int value; |
| 32 | + |
| 33 | + ModuleLogLevel(int value) { |
| 34 | + this.value = value; |
| 35 | + } |
| 36 | + |
| 37 | + public static ModuleLogLevel of(String label) { |
| 38 | + if (label == null) { |
| 39 | + return null; |
| 40 | + } |
| 41 | + try { |
| 42 | + return ModuleLogLevel.valueOf(label); |
| 43 | + } catch (IllegalArgumentException e) { |
| 44 | + return null; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + public static ModuleLogLevel of(int value) { |
| 49 | + switch (value) { |
| 50 | + case 40: |
| 51 | + return ERROR; |
| 52 | + case 30: |
| 53 | + return WARN; |
| 54 | + case 20: |
| 55 | + return INFO; |
| 56 | + case 10: |
| 57 | + return DEBUG; |
| 58 | + case 0: |
| 59 | + return TRACE; |
| 60 | + } |
| 61 | + return null; |
| 62 | + } |
| 63 | + |
| 64 | + public boolean logTrace() { |
| 65 | + return checkLevel(TRACE); |
| 66 | + } |
| 67 | + |
| 68 | + public boolean logDebug() { |
| 69 | + return checkLevel(DEBUG); |
| 70 | + } |
| 71 | + |
| 72 | + public boolean logInfo() { |
| 73 | + return checkLevel(INFO); |
| 74 | + } |
| 75 | + |
| 76 | + public boolean logWarn() { |
| 77 | + return checkLevel(WARN); |
| 78 | + } |
| 79 | + |
| 80 | + public boolean logError() { |
| 81 | + return checkLevel(ERROR); |
| 82 | + } |
| 83 | + |
| 84 | + private boolean checkLevel(ModuleLogLevel check) { |
| 85 | + return check.value >= this.value; |
| 86 | + } |
| 87 | +} |
0 commit comments