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    package org.apache.camel.component.log;
018    
019    import org.apache.camel.Component;
020    import org.apache.camel.Processor;
021    import org.apache.camel.Producer;
022    import org.apache.camel.impl.ProcessorEndpoint;
023    import org.apache.camel.spi.UriEndpoint;
024    import org.apache.camel.spi.UriParam;
025    import org.apache.camel.util.ServiceHelper;
026    
027    /**
028     * Logger endpoint.
029     */
030    @UriEndpoint(scheme = "log")
031    public class LogEndpoint extends ProcessorEndpoint {
032    
033        private volatile Processor logger;
034        @UriParam
035        private String level;
036        @UriParam
037        private String marker;
038        @UriParam
039        private Integer groupSize;
040        @UriParam
041        private Long groupInterval;
042        @UriParam
043        private Boolean groupActiveOnly;
044        @UriParam
045        private Long groupDelay;
046    
047        public LogEndpoint() {
048        }
049    
050        public LogEndpoint(String endpointUri, Component component) {
051            super(endpointUri, component);
052        }
053    
054        public LogEndpoint(String endpointUri, Component component, Processor logger) {
055            super(endpointUri, component);
056            setLogger(logger);
057        }
058    
059        @Override
060        protected void doStart() throws Exception {
061            ServiceHelper.startService(logger);
062        }
063    
064        @Override
065        protected void doStop() throws Exception {
066            ServiceHelper.stopService(logger);
067        }
068    
069        public void setLogger(Processor logger) {
070            this.logger = logger;
071            // the logger is the processor
072            setProcessor(this.logger);
073        }
074    
075        public Processor getLogger() {
076            return logger;
077        }
078    
079        @Override
080        public Producer createProducer() throws Exception {
081            return new LogProducer(this, this.logger);
082        }
083    
084        @Override
085        protected String createEndpointUri() {
086            return "log:" + logger.toString();
087        }
088    
089        public String getLevel() {
090            return level;
091        }
092    
093        public void setLevel(String level) {
094            this.level = level;
095        }
096    
097        public String getMarker() {
098            return marker;
099        }
100    
101        public void setMarker(String marker) {
102            this.marker = marker;
103        }
104    
105        public Integer getGroupSize() {
106            return groupSize;
107        }
108    
109        public void setGroupSize(Integer groupSize) {
110            this.groupSize = groupSize;
111        }
112    
113        public Long getGroupInterval() {
114            return groupInterval;
115        }
116    
117        public void setGroupInterval(Long groupInterval) {
118            this.groupInterval = groupInterval;
119        }
120    
121        public Boolean getGroupActiveOnly() {
122            return groupActiveOnly;
123        }
124    
125        public void setGroupActiveOnly(Boolean groupActiveOnly) {
126            this.groupActiveOnly = groupActiveOnly;
127        }
128    
129        public Long getGroupDelay() {
130            return groupDelay;
131        }
132    
133        public void setGroupDelay(Long groupDelay) {
134            this.groupDelay = groupDelay;
135        }
136    }