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 */ 017package org.apache.juneau.commons.io; 018 019import static org.apache.juneau.commons.utils.Utils.*; 020 021import java.text.*; 022 023/** 024 * A utility for logging formatted messages to the console. 025 * 026 * <p> 027 * Uses {@link java.text.MessageFormat} for formatting messages with arguments. 028 */ 029public class Console { 030 031 /** 032 * Constructor. 033 */ 034 public Console() { 035 } 036 037 /** 038 * Prints a message with arguments to {@link System#err}. 039 * 040 * <p> 041 * Arguments are formatted using {@link java.text.MessageFormat}. 042 * 043 * <p> 044 * Useful for debug messages. 045 * 046 * <h5 class='figure'>Example:</h5> 047 * <p class='bjava'> 048 * Console.<jsm>err</jsm>(<js>"myPojo={0}"</js>, <jv>myPojo</jv>); 049 * </p> 050 * 051 * @param msg The {@link MessageFormat}-styled message. 052 * @param args The arguments sent to the formatter. 053 */ 054 public static final void err(String msg, Object...args) { 055 System.err.println(f(msg, args)); // NOT DEBUG 056 } 057 058 /** 059 * Prints a message with arguments to {@link System#out}. 060 * 061 * <p> 062 * Arguments are formatted using {@link java.text.MessageFormat}. 063 * 064 * <p> 065 * Useful for debug messages. 066 * 067 * <h5 class='figure'>Example:</h5> 068 * <p class='bjava'> 069 * Console.<jsm>out</jsm>(<js>"myPojo={0}"</js>, <jv>myPojo</jv>); 070 * </p> 071 * 072 * @param msg The {@link MessageFormat}-styled message. 073 * @param args The arguments sent to the formatter. 074 */ 075 public static final void out(String msg, Object...args) { 076 System.out.println(f(msg, args)); 077 } 078}