MINIFI-34 Establishing CMake build system to provide build functionality equivalent...
[nifi-minifi-cpp.git] / libminifi / include / LogAttribute.h
1 /**
2 * @file LogAttribute.h
3 * LogAttribute class declaration
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one or more
6 * contributor license agreements. See the NOTICE file distributed with
7 * this work for additional information regarding copyright ownership.
8 * The ASF licenses this file to You under the Apache License, Version 2.0
9 * (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 #ifndef __LOG_ATTRIBUTE_H__
21 #define __LOG_ATTRIBUTE_H__
22
23 #include "FlowFileRecord.h"
24 #include "Processor.h"
25 #include "ProcessSession.h"
26
27 //! LogAttribute Class
28 class LogAttribute : public Processor
29 {
30 public:
31 //! Constructor
32 /*!
33 * Create a new processor
34 */
35 LogAttribute(std::string name, uuid_t uuid = NULL)
36 : Processor(name, uuid)
37 {
38 _logger = Logger::getLogger();
39 }
40 //! Destructor
41 virtual ~LogAttribute()
42 {
43 }
44 //! Processor Name
45 static const std::string ProcessorName;
46 //! Supported Properties
47 static Property LogLevel;
48 static Property AttributesToLog;
49 static Property AttributesToIgnore;
50 static Property LogPayload;
51 static Property LogPrefix;
52 //! Supported Relationships
53 static Relationship Success;
54 enum LogAttrLevel {
55 LogAttrLevelTrace, LogAttrLevelDebug, LogAttrLevelInfo, LogAttrLevelWarn, LogAttrLevelError
56 };
57 //! Convert log level from string to enum
58 bool logLevelStringToEnum(std::string logStr, LogAttrLevel &level)
59 {
60 if (logStr == "trace")
61 {
62 level = LogAttrLevelTrace;
63 return true;
64 }
65 else if (logStr == "debug")
66 {
67 level = LogAttrLevelDebug;
68 return true;
69 }
70 else if (logStr == "info")
71 {
72 level = LogAttrLevelInfo;
73 return true;
74 }
75 else if (logStr == "warn")
76 {
77 level = LogAttrLevelWarn;
78 return true;
79 }
80 else if (logStr == "error")
81 {
82 level = LogAttrLevelError;
83 return true;
84 }
85 else
86 return false;
87 }
88 //! Nest Callback Class for read stream
89 class ReadCallback : public InputStreamCallback
90 {
91 public:
92 ReadCallback(uint64_t size)
93 {
94 _bufferSize = size;
95 _buffer = new char[_bufferSize];
96 }
97 ~ReadCallback()
98 {
99 if (_buffer)
100 delete[] _buffer;
101 }
102 void process(std::ifstream *stream) {
103
104 stream->read(_buffer, _bufferSize);
105 if (!stream)
106 _readSize = stream->gcount();
107 else
108 _readSize = _bufferSize;
109 }
110 char *_buffer;
111 uint64_t _bufferSize;
112 uint64_t _readSize;
113 };
114
115 public:
116 //! OnTrigger method, implemented by NiFi LogAttribute
117 virtual void onTrigger(ProcessContext *context, ProcessSession *session);
118 //! Initialize, over write by NiFi LogAttribute
119 virtual void initialize(void);
120
121 protected:
122
123 private:
124 //! Logger
125 Logger *_logger;
126 };
127
128 #endif