|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#pragma once |
| 21 | + |
| 22 | +#include <pulsar/Logger.h> |
| 23 | + |
| 24 | +namespace pulsar { |
| 25 | + |
| 26 | +class FileLoggerFactoryImpl; |
| 27 | + |
| 28 | +/** |
| 29 | + * A logger factory that is appending logs to a single file. |
| 30 | + * |
| 31 | + * The log format is "yyyy-mm-dd hh:MM:ss.xxx <level> <thread-id> <file>:<line> | <msg>", like |
| 32 | + * |
| 33 | + * ``` |
| 34 | + * 2021-03-24 17:35:46.571 INFO [0x10a951e00] ConnectionPool:85 | Created connection for ... |
| 35 | + * ``` |
| 36 | + * |
| 37 | + * Example: |
| 38 | + * |
| 39 | + * ```c++ |
| 40 | + * #include <pulsar/FileLoggerFactory.h> |
| 41 | + * |
| 42 | + * ClientConfiguration conf; |
| 43 | + * conf.setLogger(new FileLoggerFactory(Logger::LEVEL_DEBUG, "pulsar-client-cpp.log")); |
| 44 | + * Client client("pulsar://localhost:6650", conf); |
| 45 | + * ``` |
| 46 | + */ |
| 47 | +class PULSAR_PUBLIC FileLoggerFactory : public pulsar::LoggerFactory { |
| 48 | + public: |
| 49 | + /** |
| 50 | + * Create a FileLoggerFactory instance. |
| 51 | + * |
| 52 | + * @param level the log level |
| 53 | + * @param logFilePath the log file's path |
| 54 | + */ |
| 55 | + FileLoggerFactory(Logger::Level level, const std::string& logFilePath); |
| 56 | + |
| 57 | + ~FileLoggerFactory(); |
| 58 | + |
| 59 | + pulsar::Logger* getLogger(const std::string& filename) override; |
| 60 | + |
| 61 | + private: |
| 62 | + std::unique_ptr<FileLoggerFactoryImpl> impl_; |
| 63 | +}; |
| 64 | + |
| 65 | +} // namespace pulsar |
0 commit comments