Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
LoggingPlugin.h
1 /*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2020 Sky UK
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 #ifndef LOGGINGPLUGIN_H
20 #define LOGGINGPLUGIN_H
21 
22 #include <DobbyLoggerBase.h>
23 
24 #include "IPollLoop.h"
25 #include "PollLoop.h"
26 #include "ILoggingSink.h"
27 
28 #include <sys/types.h>
29 
30 #include <unistd.h>
31 #include <string>
32 #include <memory>
33 #include <mutex>
34 
35 // Max pty buffer size is 4096
36 #define PTY_BUFFER_SIZE 4096
37 
42 {
43 public:
44  LoggingPlugin(std::shared_ptr<rt_dobby_schema> &containerConfig,
45  const std::shared_ptr<DobbyRdkPluginUtils> &utils,
46  const std::string &rootfsPath);
47 
48  ~LoggingPlugin();
49 
50 public:
51  inline std::string name() const override
52  {
53  return mName;
54  };
55 
56  unsigned hookHints() const override;
57 
58 public:
59  bool postInstallation() override;
60 
61 public:
62  std::vector<std::string> getDependencies() const override;
63 
64 public:
65  void RegisterPollSources(int fd, std::shared_ptr<AICommon::IPollLoop> pollLoop) override;
66 
67  void DumpToLog(const int bufferFd) override;
68 
69 private:
70  // Locations the plugin can send the logs
71  enum class LoggingSink
72  {
73  DevNull,
74  File,
75  Journald
76  };
77 
78 private:
79  std::shared_ptr<ILoggingSink> CreateSink(LoggingSink sinkType);
80  LoggingSink GetContainerSink();
81 
82 private:
83  const std::string mName;
84  std::shared_ptr<rt_dobby_schema> mContainerConfig;
85  const std::shared_ptr<DobbyRdkPluginUtils> mUtils;
86 
87  std::shared_ptr<ILoggingSink> mSink;
88  std::shared_ptr<AICommon::IPollLoop> mPollLoop;
89 };
90 
91 #endif // !defined(LOGGINGPLUGIN_H)
Definition: DobbyLoggerBase.h:34
Dobby Logging plugin.
Definition: LoggingPlugin.h:42
void RegisterPollSources(int fd, std::shared_ptr< AICommon::IPollLoop > pollLoop) override
Adds the necessary poll source(s) to the provided pollLoop instance based on the logging sink specifi...
Definition: LoggingPlugin.cpp:151
void DumpToLog(const int bufferFd) override
Dump the contents of a file descriptor to the log sink.
Definition: LoggingPlugin.cpp:189
LoggingSink GetContainerSink()
Converts the "sink: xxx" in the config to a valid log sink. Case insensitive.
Definition: LoggingPlugin.cpp:240
std::vector< std::string > getDependencies() const override
Should return the names of the plugins this plugin depends on.
Definition: LoggingPlugin.cpp:131
unsigned hookHints() const override
Set the bit flags for which hooks we're going to use.
Definition: LoggingPlugin.cpp:81
bool postInstallation() override
Set the correct options in the config file.
Definition: LoggingPlugin.cpp:91
LoggingPlugin(std::shared_ptr< rt_dobby_schema > &containerConfig, const std::shared_ptr< DobbyRdkPluginUtils > &utils, const std::string &rootfsPath)
Constructor - called when plugin is loaded by PluginLauncher.
Definition: LoggingPlugin.cpp:48
std::string name() const override
Should return the name of the plugin.
Definition: LoggingPlugin.h:51
std::shared_ptr< ILoggingSink > CreateSink(LoggingSink sinkType)
Constructs an instance of the requested sink.
Definition: LoggingPlugin.cpp:215