下面列出了怎么用java.lang.System.Logger.Level的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Returns all roles present in the relation.
*
* @return a RoleResult object, including a RoleList (for roles
* successfully retrieved) and a RoleUnresolvedList (for roles not
* readable).
*
* @exception RelationServiceNotRegisteredException if the Relation
* Service is not registered in the MBean Server
*/
public RoleResult getAllRoles()
throws RelationServiceNotRegisteredException {
RELATION_LOGGER.log(Level.TRACE, "ENTRY");
RoleResult result = null;
try {
result = getAllRolesInt(false, null);
} catch (IllegalArgumentException exc) {
// OK : Invalid parameters, ignore...
}
RELATION_LOGGER.log(Level.TRACE, "RETURN");
return result;
}
/**
* Constructs a new ModelMBeanAttributeInfo object from this
* ModelMBeanAttributeInfo Object. A default descriptor will
* be created.
*
* @param inInfo the ModelMBeanAttributeInfo to be duplicated
*/
public ModelMBeanAttributeInfo(ModelMBeanAttributeInfo inInfo)
{
super(inInfo.getName(),
inInfo.getType(),
inInfo.getDescription(),
inInfo.isReadable(),
inInfo.isWritable(),
inInfo.isIs());
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE,
"ModelMBeanAttributeInfo(ModelMBeanAttributeInfo) " +
"Entry");
}
Descriptor newDesc = inInfo.getDescriptor();
attrDescriptor = validDescriptor(newDesc);
}
/**
* Retrieves role value for given role name.
* <P>Checks if the role exists and is readable according to the relation
* type.
*
* @param roleName name of role
*
* @return the ArrayList of ObjectName objects being the role value
*
* @exception IllegalArgumentException if null role name
* @exception RoleNotFoundException if:
* <P>- there is no role with given name
* <P>- the role is not readable.
* @exception RelationServiceNotRegisteredException if the Relation
* Service is not registered in the MBean Server
*
* @see #setRole
*/
public List<ObjectName> getRole(String roleName)
throws IllegalArgumentException,
RoleNotFoundException,
RelationServiceNotRegisteredException {
if (roleName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", roleName);
// Can throw RoleNotFoundException and
// RelationServiceNotRegisteredException
List<ObjectName> result = cast(
getRoleInt(roleName, false, null, false));
RELATION_LOGGER.log(Level.TRACE, "RETURN");
return result;
}
private LogEvent(BootstrapLogger bootstrap,
PlatformLogger.Level platformLevel,
String sourceClass, String sourceMethod,
ResourceBundle bundle, String msg,
Throwable thrown, Object[] params) {
this.acc = AccessController.getContext();
this.timeMillis = System.currentTimeMillis();
this.nanoAdjustment = VM.getNanoTimeAdjustment(timeMillis);
this.level = null;
this.platformLevel = platformLevel;
this.bundle = bundle;
this.msg = msg;
this.msgSupplier = null;
this.thrown = thrown;
this.params = params;
this.sourceClass = sourceClass;
this.sourceMethod = sourceMethod;
this.bootstrap = bootstrap;
}
private LogEvent(BootstrapLogger bootstrap, Level level,
ResourceBundle bundle, String msg,
Throwable thrown, Object[] params) {
this.acc = AccessController.getContext();
this.timeMillis = System.currentTimeMillis();
this.nanoAdjustment = VM.getNanoTimeAdjustment(timeMillis);
this.level = level;
this.platformLevel = null;
this.bundle = bundle;
this.msg = msg;
this.msgSupplier = null;
this.thrown = thrown;
this.params = params;
this.sourceClass = null;
this.sourceMethod = null;
this.bootstrap = bootstrap;
}
/**
* Retrieves role info for given role name of a given relation type.
*
* @param relationTypeName name of relation type
* @param roleInfoName name of role
*
* @return RoleInfo object.
*
* @exception IllegalArgumentException if null parameter
* @exception RelationTypeNotFoundException if the relation type is not
* known in the Relation Service
* @exception RoleInfoNotFoundException if the role is not part of the
* relation type.
*/
public RoleInfo getRoleInfo(String relationTypeName,
String roleInfoName)
throws IllegalArgumentException,
RelationTypeNotFoundException,
RoleInfoNotFoundException {
if (relationTypeName == null || roleInfoName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1}",
relationTypeName, roleInfoName);
// Can throw a RelationTypeNotFoundException
RelationType relType = getRelationType(relationTypeName);
// Can throw a RoleInfoNotFoundException
RoleInfo roleInfo = relType.getRoleInfo(roleInfoName);
RELATION_LOGGER.log(Level.TRACE, "RETURN");
return roleInfo;
}
@Override
public void logrb(PlatformLogger.Level level, ResourceBundle bundle,
String msg, Object... params) {
if (checkBootstrapping()) {
push(LogEvent.valueOf(this, level, null, null, bundle, msg, params));
} else {
final PlatformLogger.Bridge spi = holder.platform();
spi.logrb(level, bundle, msg, params);
}
}
@Override
public void log(Level level, String msg) {
if (checkBootstrapping()) {
push(LogEvent.valueOf(this, level, null, msg, (Object[])null));
} else {
final Logger spi = holder.wrapped();
spi.log(level, msg);
}
}
@Override
public void logrb(PlatformLogger.Level level, ResourceBundle bundle,
String msg, Throwable thrown) {
final PlatformLogger.Bridge platformProxy = platformProxy();
if (platformProxy == null) {
wrapped().log(level.systemLevel(), bundle, msg, thrown);
} else {
platformProxy.logrb(level, bundle, msg, thrown);
}
}
/**
* Returns a human readable string representing the
* descriptor. The string will be in the format of
* "fieldName=fieldValue,fieldName2=fieldValue2,..."<br>
*
* If there are no fields in the descriptor, then an empty String
* is returned.<br>
*
* If a fieldValue is an object then the toString() method is
* called on it and its returned value is used as the value for
* the field enclosed in parenthesis.
*
* @exception RuntimeOperationsException for illegal value for
* field Names or field Values. If the descriptor string fails
* for any reason, this exception will be thrown.
*/
@Override
public synchronized String toString() {
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
}
String respStr = "";
String[] fields = getFields();
if ((fields == null) || (fields.length == 0)) {
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Empty Descriptor");
}
return respStr;
}
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE,
"Printing " + fields.length + " fields");
}
for (int i=0; i < fields.length; i++) {
if (i == (fields.length - 1)) {
respStr = respStr.concat(fields[i]);
} else {
respStr = respStr.concat(fields[i] + ", ");
}
}
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Exit returning " + respStr);
}
return respStr;
}
@Override
public void logp(PlatformLogger.Level level, String sourceClass,
String sourceMethod, String msg, Throwable thrown) {
if (checkBootstrapping()) {
push(LogEvent.valueOf(this, level, sourceClass, sourceMethod, null, msg, thrown));
} else {
final PlatformLogger.Bridge spi = holder.platform();
spi.logp(level, sourceClass, sourceMethod, msg, thrown);
}
}
private static String safeGetClassName(DynamicMBean mbean) {
try {
return getClassName(mbean);
} catch (Exception e) {
if (MBEANSERVER_LOGGER.isLoggable(Level.DEBUG)) {
MBEANSERVER_LOGGER.log(Level.DEBUG,
"Exception getting MBean class name", e);
}
return null;
}
}
@Override
public void log(PlatformLogger.Level level, Throwable thrown,
Supplier<String> msgSupplier) {
final PlatformLogger.Bridge platformProxy = platformProxy();
if (platformProxy == null) {
wrapped().log(level.systemLevel(), msgSupplier, thrown);
} else {
platformProxy.log(level, thrown, msgSupplier);
}
}
@Override
public void logrb(PlatformLogger.Level level, ResourceBundle bundle,
String msg, Object... params) {
final PlatformLogger.Bridge platformProxy = platformProxy();
if (platformProxy == null) {
wrapped().log(level.systemLevel(), bundle, msg, params);
} else {
platformProxy.logrb(level, bundle, msg, params);
}
}
public synchronized void removeContext (String path) throws IllegalArgumentException {
if (path == null) {
throw new NullPointerException ("null path parameter");
}
contexts.remove (protocol, path);
logger.log (Level.DEBUG, "context removed: " + path);
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, Throwable thrown,
Supplier<String> msgSupplier) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
level, null, msgSupplier, thrown, (Object[])null));
}
private void unregistering(RegistrationContext context, ObjectName name) {
if (context == null) return;
try {
context.unregistered();
} catch (Exception x) {
// shouldn't come here...
MBEANSERVER_LOGGER.log(Level.DEBUG,
"Unexpected exception while unregistering "+name,
x);
}
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, String msg) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
level, null, msg, null, (Object[])null));
}
/**
* Returns the ModelMBeanConstructorInfo requested by name.
* If no ModelMBeanConstructorInfo exists for this name null is returned.
*
* @param inName the name of the constructor.
*
* @return the constructor info for the named constructor, or null
* if there is none.
*
* @exception MBeanException Wraps a distributed communication Exception.
* @exception RuntimeOperationsException Wraps an IllegalArgumentException
* for a null constructor name.
*/
public ModelMBeanConstructorInfo getConstructor(String inName)
throws MBeanException, RuntimeOperationsException {
ModelMBeanConstructorInfo retInfo = null;
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
}
if (inName == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Constructor name is null"),
"Exception occurred trying to get the " +
"ModelMBeanConstructorInfo of the MBean");
}
MBeanConstructorInfo[] consList = modelMBeanConstructors; //this.getConstructors();
int numCons = 0;
if (consList != null) numCons = consList.length;
for (int i=0; (i < numCons) && (retInfo == null); i++) {
if (inName.equals(consList[i].getName())) {
retInfo = ((ModelMBeanConstructorInfo) consList[i].clone());
}
}
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
}
return retInfo;
}
public static LogEvent of(boolean isLoggable, String name,
Level level, ResourceBundle bundle,
String key, Throwable thrown) {
LogEvent evt = new LogEvent();
evt.isLoggable = isLoggable;
evt.loggerName = name;
evt.level = level;
evt.args = null;
evt.bundle = bundle;
evt.thrown = thrown;
evt.supplier = null;
evt.msg = key;
return evt;
}
public void removeNotificationListener(ObjectName name,
ObjectName listener)
throws InstanceNotFoundException, ListenerNotFoundException {
NotificationListener instance = getListener(listener);
if (MBEANSERVER_LOGGER.isLoggable(Level.TRACE)) {
MBEANSERVER_LOGGER.log(Level.TRACE,
"ObjectName = " + name + ", Listener = " + listener);
}
server.removeNotificationListener(name, instance);
}
@Override
public void log(Level level, ResourceBundle bundle, String key, Throwable thrown) {
if (checkBootstrapping()) {
push(LogEvent.valueOf(this, level, bundle, key, thrown));
} else {
final Logger spi = holder.wrapped();
spi.log(level, bundle, key, thrown);
}
}
@Override
public void log(Level level, ResourceBundle bundle, String format, Object... params) {
if (checkBootstrapping()) {
push(LogEvent.valueOf(this, level, bundle, format, params));
} else {
final Logger spi = holder.wrapped();
spi.log(level, bundle, format, params);
}
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, String msg, Throwable thrown) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
level, null, msg, thrown, (Object[])null));
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, Supplier<String> msgSupplier) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
level, null, msgSupplier, null, (Object[])null));
}
public static LogEvent of(boolean isLoggable, String name,
Level level, ResourceBundle bundle,
String key, Throwable thrown) {
LogEvent evt = new LogEvent();
evt.isLoggable = isLoggable;
evt.loggerName = name;
evt.level = level;
evt.args = null;
evt.bundle = bundle;
evt.thrown = thrown;
evt.supplier = null;
evt.msg = key;
return evt;
}
public ModelMBeanAttributeInfo getAttribute(String inName)
throws MBeanException, RuntimeOperationsException {
ModelMBeanAttributeInfo retInfo = null;
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
}
if (inName == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute Name is null"),
"Exception occurred trying to get the " +
"ModelMBeanAttributeInfo of the MBean");
}
MBeanAttributeInfo[] attrList = modelMBeanAttributes;
int numAttrs = 0;
if (attrList != null) numAttrs = attrList.length;
for (int i=0; (i < numAttrs) && (retInfo == null); i++) {
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
final StringBuilder strb = new StringBuilder()
.append("\t\n this.getAttributes() MBeanAttributeInfo Array ")
.append(i).append(":")
.append(((ModelMBeanAttributeInfo)attrList[i]).getDescriptor())
.append("\t\n this.modelMBeanAttributes MBeanAttributeInfo Array ")
.append(i).append(":")
.append(((ModelMBeanAttributeInfo)modelMBeanAttributes[i]).getDescriptor());
MODELMBEAN_LOGGER.log(Level.TRACE, strb::toString);
}
if (inName.equals(attrList[i].getName())) {
retInfo = ((ModelMBeanAttributeInfo)attrList[i].clone());
}
}
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
}
return retInfo;
}
@Override
public void log(PlatformLogger.Level level, Supplier<String> msgSupplier) {
if (checkBootstrapping()) {
push(LogEvent.valueOf(this, level, msgSupplier));
} else {
final PlatformLogger.Bridge spi = holder.platform();
spi.log(level, msgSupplier);
}
}
@Override
public void log(Level level, String string, Object... os) {
try {
invoke(System.Logger.class.getMethod(
"log", Level.class, String.class, Object[].class),
level, string, os);
} catch (NoSuchMethodException ex) {
throw new RuntimeException(ex);
}
}
@Override
public void logp(PlatformLogger.Level level, String sourceClass,
String sourceMethod, String msg) {
if (checkBootstrapping()) {
push(LogEvent.valueOf(this, level, sourceClass, sourceMethod, null,
msg, (Object[])null));
} else {
final PlatformLogger.Bridge spi = holder.platform();
spi.logp(level, sourceClass, sourceMethod, msg);
}
}