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.camel.model; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlTransient; 024 025import org.apache.camel.LoggingLevel; 026import org.apache.camel.spi.Metadata; 027import org.slf4j.Logger; 028 029/** 030 * Logs the defined message to the logger 031 */ 032@Metadata(label = "eip,configuration") 033@XmlRootElement(name = "log") 034@XmlAccessorType(XmlAccessType.FIELD) 035public class LogDefinition extends NoOutputDefinition<LogDefinition> { 036 037 @XmlAttribute(required = true) 038 private String message; 039 @XmlAttribute 040 @Metadata(defaultValue = "INFO") 041 private LoggingLevel loggingLevel; 042 @XmlAttribute 043 private String logName; 044 @XmlAttribute 045 private String marker; 046 @XmlAttribute 047 private String loggerRef; 048 @XmlTransient 049 private Logger logger; 050 051 public LogDefinition() { 052 } 053 054 public LogDefinition(String message) { 055 this(); 056 this.message = message; 057 } 058 059 @Override 060 public String toString() { 061 return "Log[" + message + "]"; 062 } 063 064 @Override 065 public String getShortName() { 066 return "log"; 067 } 068 069 @Override 070 public String getLabel() { 071 return "log"; 072 } 073 074 public LoggingLevel getLoggingLevel() { 075 return loggingLevel; 076 } 077 078 /** 079 * Sets the logging level. 080 * <p/> 081 * The default value is INFO 082 */ 083 public void setLoggingLevel(LoggingLevel loggingLevel) { 084 this.loggingLevel = loggingLevel; 085 } 086 087 public String getMessage() { 088 return message; 089 } 090 091 /** 092 * Sets the log message (uses simple language) 093 */ 094 public void setMessage(String message) { 095 this.message = message; 096 } 097 098 public String getLogName() { 099 return logName; 100 } 101 102 /** 103 * Sets the name of the logger 104 */ 105 public void setLogName(String logName) { 106 this.logName = logName; 107 } 108 109 public String getMarker() { 110 return marker; 111 } 112 113 /** 114 * To use slf4j marker 115 */ 116 public void setMarker(String marker) { 117 this.marker = marker; 118 } 119 120 public String getLoggerRef() { 121 return loggerRef; 122 } 123 124 /** 125 * To refer to a custom logger instance to lookup from the registry. 126 */ 127 public void setLoggerRef(String loggerRef) { 128 this.loggerRef = loggerRef; 129 } 130 131 public Logger getLogger() { 132 return logger; 133 } 134 135 /** 136 * To use a custom logger instance 137 */ 138 public void setLogger(Logger logger) { 139 this.logger = logger; 140 } 141 142}