-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flexible loggers' support through SPI mechanism with name `com.alibab…
…a.csp.sentinel.log.Logger` (#1265) * There are two types of logger for command center and common modules specified by annotation of `LogTarget` * Add implementing examples in `sentinel-demo/sentinel-demo-log-logback` * All implementations should support placeholder '{}'
- Loading branch information
Showing
20 changed files
with
1,476 additions
and
38 deletions.
There are no files selected for viewing
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
79 changes: 79 additions & 0 deletions
79
sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/CommandCenterLogLogging.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 1999-2019 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.csp.sentinel.log; | ||
|
||
import java.util.logging.Handler; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Default logger implementation. | ||
* @author xue8 | ||
*/ | ||
public class CommandCenterLogLogging extends LogBase implements com.alibaba.csp.sentinel.log.Logger { | ||
private final Logger heliumRecordLog = Logger.getLogger("cspCommandCenterLog"); | ||
private final String FILE_NAME = "command-center.log"; | ||
private final Handler logHandler = makeLogger(FILE_NAME, heliumRecordLog); | ||
|
||
@Override | ||
public void info(String format, Object... arguments) { | ||
log(heliumRecordLog, logHandler, Level.INFO, format, arguments); | ||
} | ||
|
||
@Override | ||
public void info(String msg, Throwable e) { | ||
log(heliumRecordLog, logHandler, Level.INFO, msg, e); | ||
} | ||
|
||
@Override | ||
public void warn(String format, Object... arguments) { | ||
log(heliumRecordLog, logHandler, Level.WARNING, format, arguments); | ||
} | ||
|
||
@Override | ||
public void warn(String msg, Throwable e) { | ||
log(heliumRecordLog, logHandler, Level.WARNING, msg, e); | ||
} | ||
|
||
@Override | ||
public void trace(String format, Object... arguments) { | ||
log(heliumRecordLog, logHandler, Level.TRACE, format, arguments); | ||
} | ||
|
||
@Override | ||
public void trace(String msg, Throwable e) { | ||
log(heliumRecordLog, logHandler, Level.TRACE, msg, e); | ||
} | ||
|
||
@Override | ||
public void debug(String format, Object... arguments) { | ||
log(heliumRecordLog, logHandler, Level.DEBUG, format, arguments); | ||
} | ||
|
||
@Override | ||
public void debug(String msg, Throwable e) { | ||
log(heliumRecordLog, logHandler, Level.DEBUG, msg, e); | ||
} | ||
|
||
@Override | ||
public void error(String format, Object... arguments) { | ||
log(heliumRecordLog, logHandler, Level.ERROR, format, arguments); | ||
} | ||
|
||
@Override | ||
public void error(String msg, Throwable e) { | ||
log(heliumRecordLog, logHandler, Level.ERROR, msg, e); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/FormattingTuple.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Copyright notice | ||
* This code copy from SLF4J which licensed under the MIT License. | ||
* | ||
*/ | ||
package com.alibaba.csp.sentinel.log; | ||
|
||
/** | ||
* Holds the results of formatting done by {@link MessageFormatter}. | ||
* | ||
* @author Joern Huxhorn | ||
*/ | ||
public class FormattingTuple { | ||
|
||
static public FormattingTuple NULL = new FormattingTuple(null); | ||
|
||
private String message; | ||
private Throwable throwable; | ||
private Object[] argArray; | ||
|
||
public FormattingTuple(String message) { | ||
this(message, null, null); | ||
} | ||
|
||
public FormattingTuple(String message, Object[] argArray, Throwable throwable) { | ||
this.message = message; | ||
this.throwable = throwable; | ||
this.argArray = argArray; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public Object[] getArgArray() { | ||
return argArray; | ||
} | ||
|
||
public Throwable getThrowable() { | ||
return throwable; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/Level.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 1999-2019 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.csp.sentinel.log; | ||
|
||
/** | ||
* Logging levels | ||
* @author xue8 | ||
*/ | ||
public class Level extends java.util.logging.Level { | ||
private static final String defaultBundle = "sun.util.logging.resources.logging"; | ||
|
||
public static final Level ERROR = new Level("ERROR", 1000); | ||
public static final Level WARNING = new Level("WARNING", 900); | ||
public static final Level INFO = new Level("INFO", 800); | ||
public static final Level DEBUG = new Level("DEBUG", 700); | ||
public static final Level TRACE = new Level("TRACE", 600); | ||
|
||
protected Level(String name, int value) { | ||
super(name, value, defaultBundle); | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/LogTarget.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 1999-2019 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.csp.sentinel.log; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* @author xue8 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Documented | ||
public @interface LogTarget { | ||
/** | ||
* Returns the kinds of log type. | ||
* @return Returns the kinds of log type | ||
*/ | ||
LogType value() default LogType.RECORD_LOG; | ||
} |
25 changes: 25 additions & 0 deletions
25
sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/LogType.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 1999-2019 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.csp.sentinel.log; | ||
|
||
/** | ||
* An enum marks log type. | ||
* @author xue8 | ||
*/ | ||
public enum LogType { | ||
COMMAND_CENTER_LOG, | ||
RECORD_LOG, | ||
} |
Oops, something went wrong.