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.Shorts.*; 020 021/** 022 * A utility for logging formatted messages to the console. 023 * 024 * <p> 025 * Uses printf-style ({@code %s}/{@code %d}/…) formatting for messages with arguments. 026 */ 027@SuppressWarnings({ 028 "java:S106", // System.err/out usage is intentional for console output utility 029 "java:S108" // Nested blocks used for logical grouping in console operations 030}) 031public class Console { 032 033 /** 034 * Constructor. 035 */ 036 private Console() { 037 // No-op: Intentional empty constructor 038 } 039 040 /** 041 * Prints a message with arguments to {@link System#err}. 042 * 043 * <p> 044 * Arguments are formatted using printf-style ({@code %s}) placeholders. 045 * 046 * <p> 047 * Useful for debug messages. 048 * 049 * <h5 class='figure'>Example:</h5> 050 * <p class='bjava'> 051 * Console.<jsm>err</jsm>(<js>"myPojo=%s"</js>, <jv>myPojo</jv>); 052 * </p> 053 * 054 * @param msg The printf-styled message. 055 * @param args The arguments sent to the formatter. 056 */ 057 public static final void err(String msg, Object...args) { 058 System.err.println(f(msg, args)); // NOT DEBUG 059 } 060 061 /** 062 * Prints a message with arguments to {@link System#out}. 063 * 064 * <p> 065 * Arguments are formatted using printf-style ({@code %s}) placeholders. 066 * 067 * <p> 068 * Useful for debug messages. 069 * 070 * <h5 class='figure'>Example:</h5> 071 * <p class='bjava'> 072 * Console.<jsm>out</jsm>(<js>"myPojo=%s"</js>, <jv>myPojo</jv>); 073 * </p> 074 * 075 * @param msg The printf-styled message. 076 * @param args The arguments sent to the formatter. 077 */ 078 public static final void out(String msg, Object...args) { 079 System.out.println(f(msg, args)); 080 } 081}