001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.util;
019:
020: import java.util.List;
021:
022: import org.apache.ivy.Ivy;
023: import org.apache.ivy.core.IvyContext;
024:
025: /**
026: * Logging utility class.
027: * <p>
028: * This class provides static methods for easy access to the current logger in {@link IvyContext}.
029: * </p>
030: * <p>
031: * To configure logging, you should use the methods provided by the {@link MessageLoggerEngine}
032: * associated with the {@link Ivy} engine.
033: * </p>
034: */
035: public final class Message {
036: // messages level copied from ant project, to avoid dependency on ant
037: /** Message priority of "error". */
038: public static final int MSG_ERR = 0;
039:
040: /** Message priority of "warning". */
041: public static final int MSG_WARN = 1;
042:
043: /** Message priority of "information". */
044: public static final int MSG_INFO = 2;
045:
046: /** Message priority of "verbose". */
047: public static final int MSG_VERBOSE = 3;
048:
049: /** Message priority of "debug". */
050: public static final int MSG_DEBUG = 4;
051:
052: private static boolean showedInfo = false;
053:
054: private static MessageLogger defaultLogger = new DefaultMessageLogger(
055: Message.MSG_INFO);
056:
057: /**
058: * Returns the current default logger.
059: * @return the current default logger; is never <code>null</code>.
060: */
061: public static MessageLogger getDefaultLogger() {
062: return defaultLogger;
063: }
064:
065: /**
066: * Change the default logger used when no other logger is currently configured
067: * @param logger the new default logger, must not be <code>null</code>
068: */
069: public static void setDefaultLogger(MessageLogger logger) {
070: Checks.checkNotNull(logger, "logger");
071: defaultLogger = logger;
072: }
073:
074: private static MessageLogger getLogger() {
075: return IvyContext.getContext().getMessageLogger();
076: }
077:
078: public static void showInfo() {
079: if (!showedInfo) {
080: info(":: Ivy " + Ivy.getIvyVersion() + " - "
081: + Ivy.getIvyDate() + " :: " + Ivy.getIvyHomeURL()
082: + " ::");
083: showedInfo = true;
084: }
085: }
086:
087: public static void debug(String msg) {
088: getLogger().debug(msg);
089: }
090:
091: public static void verbose(String msg) {
092: getLogger().verbose(msg);
093: }
094:
095: public static void info(String msg) {
096: getLogger().info(msg);
097: }
098:
099: public static void rawinfo(String msg) {
100: getLogger().rawinfo(msg);
101: }
102:
103: public static void deprecated(String msg) {
104: getLogger().deprecated(msg);
105: }
106:
107: public static void warn(String msg) {
108: getLogger().warn(msg);
109: }
110:
111: public static void error(String msg) {
112: getLogger().error(msg);
113: }
114:
115: public static List getProblems() {
116: return getLogger().getProblems();
117: }
118:
119: public static void sumupProblems() {
120: getLogger().sumupProblems();
121: }
122:
123: public static void progress() {
124: getLogger().progress();
125: }
126:
127: public static void endProgress() {
128: getLogger().endProgress();
129: }
130:
131: public static void endProgress(String msg) {
132: getLogger().endProgress(msg);
133: }
134:
135: public static boolean isShowProgress() {
136: return getLogger().isShowProgress();
137: }
138:
139: public static void setShowProgress(boolean progress) {
140: getLogger().setShowProgress(progress);
141: }
142:
143: private Message() {
144: }
145: }
|