List of usage examples for org.apache.commons.logging Log warn
void warn(Object message, Throwable t);
From source file:com.microsoft.gittf.client.clc.Main.java
public static void main(String[] args) { // Configure logging, use the standard TFS SDK logging. System.setProperty("teamexplorer.application", ProductInformation.getProductName()); //$NON-NLS-1$ LoggingConfiguration.configure();/*ww w. jav a2s . c o m*/ final Log log = LogFactory.getLog(ProductInformation.getProductName()); try { ArgumentCollection mainArguments = new ArgumentCollection(); try { mainArguments = ArgumentParser.parse(args, ARGUMENTS, ArgumentParserOptions.ALLOW_UNKNOWN_ARGUMENTS); } catch (ArgumentParserException e) { console.getErrorStream().println(e.getLocalizedMessage()); console.getErrorStream().println(getUsage()); System.exit(ExitCode.FAILURE); } if (mainArguments.contains("version")) //$NON-NLS-1$ { console.getOutputStream().println(Messages.formatString("Main.ApplicationVersionFormat", //$NON-NLS-1$ ProductInformation.getProductName(), ProductInformation.getBuildNumber())); return; } /* * Special case "--help command" handling - convert to * "help command" */ if (mainArguments.contains("help") && mainArguments.contains("command")) //$NON-NLS-1$ //$NON-NLS-2$ { HelpCommand helpCommand = new HelpCommand(); helpCommand.setArguments(ArgumentParser.parse(new String[] { ((FreeArgumentCollection) mainArguments.getArgument("command")).getValues()[0] //$NON-NLS-1$ }, helpCommand.getPossibleArguments())); helpCommand.setConsole(console); helpCommand.run(); return; } else if (mainArguments.contains("help") || !mainArguments.contains("command")) //$NON-NLS-1$ //$NON-NLS-2$ { showHelp(); return; } // Set the verbosity of the console from the arguments. if (mainArguments.contains("quiet")) //$NON-NLS-1$ { console.setVerbosity(Verbosity.QUIET); } else if (mainArguments.contains("verbose")) //$NON-NLS-1$ { console.setVerbosity(Verbosity.VERBOSE); } /* * Parse the free arguments into the command name and arguments to * pass to it. Add any unmatched arguments that were specified on * the command line before the argument. (eg, for * "git-tf --bare clone", we parsed the "--bare" as an unmatched * argument to the main command. We instead want to add the "--bare" * as an argument to "clone".) */ String[] fullCommand = ((FreeArgumentCollection) mainArguments.getArgument("command")).getValues(); //$NON-NLS-1$ String[] additionalArguments = mainArguments.getUnknownArguments(); String commandName = fullCommand[0]; String[] commandArgs = new String[additionalArguments.length + (fullCommand.length - 1)]; if (additionalArguments.length > 0) { System.arraycopy(additionalArguments, 0, commandArgs, 0, additionalArguments.length); } if (fullCommand.length > 1) { System.arraycopy(fullCommand, 1, commandArgs, mainArguments.getUnknownArguments().length, fullCommand.length - 1); } // Locate the specified command by name List<CommandDefinition> possibleCommands = new ArrayList<CommandDefinition>(); for (CommandDefinition c : COMMANDS) { if (c.getName().equals(commandName)) { possibleCommands.clear(); possibleCommands.add(c); break; } else if (c.getName().startsWith(commandName)) { possibleCommands.add(c); } } if (possibleCommands.size() == 0) { printError(Messages.formatString("Main.CommandNotFoundFormat", commandName, //$NON-NLS-1$ ProductInformation.getProductName())); System.exit(1); } if (possibleCommands.size() > 1) { printError(Messages.formatString("Main.AmbiguousCommandFormat", commandName, //$NON-NLS-1$ ProductInformation.getProductName())); for (CommandDefinition c : possibleCommands) { printError(Messages.formatString("Main.AmbiguousCommandListFormat", c.getName()), false); //$NON-NLS-1$ } System.exit(1); } // Instantiate the command final CommandDefinition commandDefinition = possibleCommands.get(0); Command command = null; try { command = commandDefinition.getType().newInstance(); } catch (Exception e) { printError(Messages.formatString("Main.CommandCreationFailedFormat", commandName)); //$NON-NLS-1$ System.exit(1); } // Set the console command.setConsole(console); // Parse the arguments ArgumentCollection argumentCollection = null; try { argumentCollection = ArgumentParser.parse(commandArgs, command.getPossibleArguments()); } catch (ArgumentParserException e) { Main.printError(e.getLocalizedMessage()); Main.printError(getUsage(command)); log.error("Could not parse arguments", e); //$NON-NLS-1$ System.exit(1); } // Handle the --help argument directly if (argumentCollection.contains("help")) //$NON-NLS-1$ { command.showHelp(); System.exit(0); } // Set the verbosity of the console from the arguments. if (argumentCollection.contains("quiet")) //$NON-NLS-1$ { console.setVerbosity(Verbosity.QUIET); } else if (argumentCollection.contains("verbose")) //$NON-NLS-1$ { console.setVerbosity(Verbosity.VERBOSE); } command.setArguments(argumentCollection); System.exit(command.run()); } catch (Exception e) { printError(e.getLocalizedMessage()); log.warn(MessageFormat.format("Error executing command: {0}", getCommandLine(args)), e); //$NON-NLS-1$ } }
From source file:com.thoughtworks.go.agent.bootstrapper.BootstrapperLoggingHelper.java
private static void setupDefaultLog4j() { String logFile = System.getenv("LOG_FILE"); System.out.println("logFile Environment Variable= " + logFile); try {/*from w w w . ja v a2 s . c o m*/ if (logFile == null) { logFile = "go-agent-bootstrapper.log"; } System.out.println("Logging to " + logFile); BasicConfigurator.configure(new FileAppender(LOG4J_PATTERN, logFile)); Logger.getRootLogger().setLevel(Level.INFO); } catch (IOException e) { BasicConfigurator.configure(new ConsoleAppender(LOG4J_PATTERN)); Logger.getRootLogger().setLevel(Level.INFO); Log LOG = LogFactory.getLog(BootstrapperLoggingHelper.class); LOG.warn("Unable to initialize log4j file-appender: " + logFile, e); LOG.warn("Using console-appender instead"); } }
From source file:com.buffalokiwi.api.APILog.java
/** * Log an error with warn log level./* www . j ava 2 s .com*/ * * @param log Log to write to * @param message log this message * @param t log this cause */ public static void warn(final Log log, final Throwable t, final Object... message) { if (log.isWarnEnabled()) log.warn(concat(message), t); }
From source file:net.gleamynode.netty2.SessionLog.java
public static void warn(Log log, Session session, Object obj, Throwable cause) { log.warn(getMessage(session, obj), cause); }
From source file:com.datos.vfs.VfsLog.java
/** * warning./*from ww w. java2s . c o m*/ * @param vfslog The base component Logger to use. * @param commonslog The class specific Logger * @param message The message to log. * @param t The exception, if any. */ public static void warn(final Log vfslog, final Log commonslog, final String message, final Throwable t) { if (vfslog != null) { vfslog.warn(message, t); } else if (commonslog != null) { commonslog.warn(message, t); } }
From source file:com.headissue.pigeon.util.LogUtils.java
public static void warn(Log log, Throwable t, String message, Object... args) { if (log.isWarnEnabled()) { if (args != null && args.length > 0) { message = String.format(message, args); }// ww w. j a v a2 s . c om log.warn(message, t); } }
From source file:net.sf.nmedit.jtheme.image.SVGImageResource.java
private static Image renderSVGImage(Reader source, int width, int height) { ImageTranscoder pngt = new PNGTranscoder(); TranscoderInput input = new TranscoderInput(source); ByteArrayOutputStream out = new ByteArrayOutputStream(8096); try {/*from w w w. j ava2 s . c om*/ TranscoderOutput output = new TranscoderOutput(out); if (width > 0 && height > 0) { Float w = new Float(width); pngt.addTranscodingHint(PNGTranscoder.KEY_WIDTH, w); pngt.addTranscodingHint(PNGTranscoder.KEY_MAX_WIDTH, w); Float h = new Float(height); pngt.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, h); pngt.addTranscodingHint(PNGTranscoder.KEY_MAX_HEIGHT, h); } // TODO other solution for SAX parser / class loader issue ? Thread.currentThread().setContextClassLoader(ImageResource.class.getClassLoader()); // Save the image. try { pngt.transcode(input, output); } catch (TranscoderException e) { Log log = LogFactory.getLog(ImageResource.class); if (log.isWarnEnabled()) { log.warn("could not render image", e); } return null; } } finally { try { source.close(); } catch (IOException e) { Log log = LogFactory.getLog(ImageResource.class); if (log.isWarnEnabled()) { log.warn("could not close stream", e); } } } return Toolkit.getDefaultToolkit().createImage(out.toByteArray()); }
From source file:net.sf.nmedit.jtheme.store2.ImageElement.java
public static String element2txt(Element el) { TransformerFactory tf = TransformerFactory.newInstance(); // set all necessary features for your transformer -> see OutputKeys Transformer t;//from w w w .j av a 2s .c o m try { t = tf.newTransformer(); } catch (TransformerConfigurationException e) { return null; } StringWriter sw = new StringWriter(); try { t.transform(new JDOMSource(el), new StreamResult(sw)); } catch (TransformerException e) { Log log = getLogger(); if (log.isWarnEnabled()) { log.warn("element2txt failed", e); } return null; } return sw.toString(); }
From source file:es.tunelator.log.Logger.java
/** * @param source/*from w w w . j a v a 2 s . c o m*/ * @param msg * @param e */ public static void logWarning(Class source, String msg, Throwable e) { Log log = LogFactory.getLog(es.tunelator.AppParameters.LOG_WARN); // Log log = LogFactory.getLog(source); log.warn(msg, e); }
From source file:net.sf.nmedit.nordmodular.NmFileService.java
public static NMPatch openPatch(File file, File sourceFile, final String title, boolean showExceptionDialog) { NMContextData data = NMContextData.sharedInstance(); try {//from ww w .ja va 2 s . com boolean setFilePointerToNull = false; if (isFileAlreadyOpen(file)) { if (JOptionPane.showConfirmDialog(Nomad.sharedInstance().getWindow().getRootPane(), "File \"" + file + "\" is already open.\nDo you want to open a copy of the file?", "Open...", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) { Nomad.sharedInstance().setSelectedDocumentByFile(file); return null; } setFilePointerToNull = true; } NMPatch patch = NMPatch.createPatchFromFile(file); patch.setEditSupportEnabled(false); if (title != null) patch.setName(title); final PatchDocument pd = createPatchDoc(patch); if (setFilePointerToNull) { if (sourceFile != null) { String name = sourceFile.getName(); if (name.toLowerCase().endsWith(".pch")) name = name.substring(0, name.length() - 4); patch.setName(name); } } else { if (sourceFile != null) { patch.setProperty("file", sourceFile); pd.setURI(sourceFile); } } patch.setEditSupportEnabled(true); patch.setModified(false); DocumentManager dm = Nomad.sharedInstance().getDocumentManager(); dm.add(pd); dm.setSelection(pd); return patch; } catch (Exception e) { Log log = LogFactory.getLog(NmFileService.class); if (log.isWarnEnabled()) { log.warn("open failed: " + file, e); } if (showExceptionDialog) { ExceptionDialog.showErrorDialog(Nomad.sharedInstance().getWindow().getRootPane(), "Could not open file '" + file + "' (" + e.getMessage() + ")", "Could not open file", e); } } return null; }