Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-7284: Introduce DEV_ONLY marker to IgniteLogger #3346

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/ignite-log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
</Console>

<Console name="CONSOLE_ERR" target="SYSTEM_ERR">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
</Console>

<Routing name="FILE">
<Routes pattern="$${sys:nodeId}">
<Route>
<RollingFile name="Rolling-${sys:nodeId}" fileName="${sys:IGNITE_HOME}/work/log/ignite-${sys:nodeId}.log"
filePattern="${sys:IGNITE_HOME}/work/log/ignite-${sys:nodeId}-%i-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
Expand Down
102 changes: 89 additions & 13 deletions modules/core/src/main/java/org/apache/ignite/IgniteLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,97 +65,173 @@
*/
@GridToStringExclude
public interface IgniteLogger {
/**
* Marker for log messages that are useful in development environments, but not in production.
*/
String DEV_ONLY = "DEV_ONLY";

/**
* Creates new logger with given category based off the current instance.
*
* @param ctgr Category for new logger.
* @return New logger with given category.
*/
public IgniteLogger getLogger(Object ctgr);
IgniteLogger getLogger(Object ctgr);

/**
* Logs out trace message.
*
* @param msg Trace message.
*/
void trace(String msg);

/**
* Logs out trace message.
*
* @implSpec
* The default implementation calls {@code this.trace(msg)}.
*
* @param marker Name of the marker to be associated with the message.
* @param msg Trace message.
*/
public void trace(String msg);
default void trace(@Nullable String marker, String msg) {
trace(msg);
}

/**
* Logs out debug message.
*
* @param msg Debug message.
*/
public void debug(String msg);
void debug(String msg);

/**
* Logs out debug message.
*
* @implSpec
* The default implementation calls {@code this.debug(msg)}.
*
* @param marker Name of the marker to be associated with the message.
* @param msg Debug message.
*/
default void debug(@Nullable String marker, String msg) {
debug(msg);
}

/**
* Logs out information message.
*
* @param msg Information message.
*/
void info(String msg);

/**
* Logs out information message.
*
* @implSpec
* The default implementation calls {@code this.info(msg)}.
*
* @param marker Name of the marker to be associated with the message.
* @param msg Information message.
*/
public void info(String msg);
default void info(@Nullable String marker, String msg) {
info(msg);
}

/**
* Logs out warning message.
*
* @param msg Warning message.
*/
public void warning(String msg);
default void warning(String msg) {
warning(msg, null);
}

/**
* Logs out warning message with optional exception.
*
* @param msg Warning message.
* @param e Optional exception (can be {@code null}).
*/
void warning(String msg, @Nullable Throwable e);

/**
* Logs out warning message with optional exception.
*
* @implSpec
* The default implementation calls {@code this.warning(msg)}.
*
* @param marker Name of the marker to be associated with the message.
* @param msg Warning message.
* @param e Optional exception (can be {@code null}).
*/
public void warning(String msg, @Nullable Throwable e);
default void warning(@Nullable String marker, String msg, @Nullable Throwable e) {
warning(msg, e);
}

/**
* Logs out error message.
*
* @param msg Error message.
*/
public void error(String msg);
default void error(String msg) {
error(null, msg, null);
}

/**
* Logs error message with optional exception.
*
* @param msg Error message.
* @param e Optional exception (can be {@code null}).
*/
void error(String msg, @Nullable Throwable e);

/**
* Logs error message with optional exception.
*
* @implSpec
* The default implementation calls {@code this.error(msg)}.
*
* @param marker Name of the marker to be associated with the message.
* @param msg Error message.
* @param e Optional exception (can be {@code null}).
*/
public void error(String msg, @Nullable Throwable e);
default void error(@Nullable String marker, String msg, @Nullable Throwable e) {
error(msg, e);
}

/**
* Tests whether {@code trace} level is enabled.
*
* @return {@code true} in case when {@code trace} level is enabled, {@code false} otherwise.
*/
public boolean isTraceEnabled();
boolean isTraceEnabled();

/**
* Tests whether {@code debug} level is enabled.
*
* @return {@code true} in case when {@code debug} level is enabled, {@code false} otherwise.
*/
public boolean isDebugEnabled();
boolean isDebugEnabled();

/**
* Tests whether {@code info} level is enabled.
*
* @return {@code true} in case when {@code info} level is enabled, {@code false} otherwise.
*/
public boolean isInfoEnabled();
boolean isInfoEnabled();

/**
* Tests whether Logger is in "Quiet mode".
*
* @return {@code true} "Quiet mode" is enabled, {@code false} otherwise
*/
public boolean isQuiet();
boolean isQuiet();

/**
* Gets name of the file being logged to if one is configured or {@code null} otherwise.
*
* @return Name of the file being logged to if one is configured or {@code null} otherwise.
*/
public String fileName();
String fileName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,12 @@ public final class IgniteSystemProperties {
*/
public static final String IGNITE_GRID_CLIENT_LOG_ENABLED = "IGNITE_GRID_CLIENT_LOG_ENABLED";

/**
* When set to {@code true}, warnings that are intended for development environments and not for production
* (such as coding mistakes in code using Ignite) will not be logged.
*/
public static final String IGNITE_DEV_ONLY_LOGGING_DISABLED = "IGNITE_DEV_ONLY_LOGGING_DISABLED";

/**
* Enforces singleton.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,31 @@ public GridLoggerProxy(IgniteLogger impl, @Nullable Object ctgr, @Nullable Strin
impl.trace(enrich(msg));
}

/** {@inheritDoc} */
@Override public void trace(@Nullable String marker, String msg) {
impl.trace(marker, enrich(msg));
}

/** {@inheritDoc} */
@Override public void debug(String msg) {
impl.debug(enrich(msg));
}

/** {@inheritDoc} */
@Override public void debug(@Nullable String marker, String msg) {
impl.debug(marker, enrich(msg));
}

/** {@inheritDoc} */
@Override public void info(String msg) {
impl.info(enrich(msg));
}

/** {@inheritDoc} */
@Override public void info(@Nullable String marker, String msg) {
impl.info(marker, enrich(msg));
}

/** {@inheritDoc} */
@Override public void warning(String msg) {
impl.warning(enrich(msg));
Expand All @@ -138,6 +153,11 @@ public GridLoggerProxy(IgniteLogger impl, @Nullable Object ctgr, @Nullable Strin
impl.warning(enrich(msg), e);
}

/** {@inheritDoc} */
@Override public void warning(@Nullable String marker, String msg, @Nullable Throwable e) {
impl.warning(marker, enrich(msg), e);
}

/** {@inheritDoc} */
@Override public void error(String msg) {
impl.error(enrich(msg));
Expand All @@ -148,6 +168,11 @@ public GridLoggerProxy(IgniteLogger impl, @Nullable Object ctgr, @Nullable Strin
impl.error(enrich(msg), e);
}

/** {@inheritDoc} */
@Override public void error(@Nullable String marker, String msg, @Nullable Throwable e) {
impl.error(marker, enrich(msg), e);
}

/** {@inheritDoc} */
@Override public boolean isTraceEnabled() {
return impl.isTraceEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ else if (useOptMarshaller)
}

if (useOptMarshaller && userType && !U.isIgnite(cls) && !U.isJdk(cls) && !QueryUtils.isGeometryClass(cls)) {
U.warn(ctx.log(), "Class \"" + cls.getName() + "\" cannot be serialized using " +
U.warnDevOnly(ctx.log(), "Class \"" + cls.getName() + "\" cannot be serialized using " +
BinaryMarshaller.class.getSimpleName() + " because it either implements Externalizable interface " +
"or have writeObject/readObject methods. " + OptimizedMarshaller.class.getSimpleName() + " will be " +
"used instead and class instances will be deserialized on the server. Please ensure that all nodes " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@
import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
import org.apache.ignite.internal.processors.cache.KeyCacheObject;
import org.apache.ignite.internal.processors.cache.StoredCacheData;
import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture;
import org.apache.ignite.internal.processors.cache.query.CacheQueryType;
Expand Down Expand Up @@ -800,7 +798,7 @@ else if (op0 instanceof SchemaAlterTableDropColumnOperation) {

// Warn about possible implicit deserialization.
if (!mustDeserializeClss.isEmpty()) {
U.warn(log, "Some classes in query configuration cannot be written in binary format " +
U.warnDevOnly(log, "Some classes in query configuration cannot be written in binary format " +
"because they either implement Externalizable interface or have writeObject/readObject " +
"methods. Instances of these classes will be deserialized in order to build indexes. Please " +
"ensure that all nodes have these classes in classpath. To enable binary serialization " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4266,6 +4266,30 @@ public static void warn(@Nullable IgniteLogger log, Object longMsg, Object short
compact(shortMsg.toString()));
}

/**
* Depending on whether or not log is provided and quiet mode is enabled logs given
* messages as quiet message or normal log WARN message with {@link IgniteLogger#DEV_ONLY DEV_ONLY} marker.
* If {@code log} is {@code null} or in QUIET mode it will add {@code (wrn)} prefix to the message.
* If property {@link IgniteSystemProperties#IGNITE_DEV_ONLY_LOGGING_DISABLED IGNITE_DEV_ONLY_LOGGING_DISABLED}
* is set to true, the message will not be logged.
*
* @param log Optional logger to use when QUIET mode is not enabled.
* @param msg Message to log.
*/
public static void warnDevOnly(@Nullable IgniteLogger log, Object msg) {
assert msg != null;

// don't log message if DEV_ONLY messages are disabled
if (IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_DEV_ONLY_LOGGING_DISABLED))
return;

if (log != null)
log.warning(IgniteLogger.DEV_ONLY, compact(msg.toString()), null);
else
X.println("[" + SHORT_DATE_FMT.format(new java.util.Date()) + "] (wrn) " +
compact(msg.toString()));
}

/**
* Depending on whether or not log is provided and quiet mode is enabled logs given
* messages as quiet message or normal log INFO message.
Expand Down
6 changes: 3 additions & 3 deletions modules/core/src/test/config/log4j2-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
</Console>

<Console name="CONSOLE_ERR" target="SYSTEM_ERR">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
</Console>

<Routing name="FILE">
<Routes pattern="$${sys:nodeId}">
<Route>
<RollingFile name="Rolling-${sys:nodeId}" fileName="${sys:IGNITE_HOME}/work/log/ignite-${sys:nodeId}.log"
filePattern="${sys:IGNITE_HOME}/work/log/ignite-${sys:nodeId}-%i-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/test/config/log4j2-verbose-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
<Configuration>
<Appenders>
<Console name="CONSOLE_ERR" target="SYSTEM_ERR">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
</Console>

<Routing name="FILE">
<Routes pattern="$${sys:nodeId}">
<Route>
<RollingFile name="Rolling-${sys:nodeId}" fileName="${sys:IGNITE_HOME}/work/log/ignite-${sys:nodeId}.log"
filePattern="${sys:IGNITE_HOME}/work/log/ignite-${sys:nodeId}-%i-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
Expand Down
Loading