Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding minute_file_sink_mt #2727

Closed
mmanoj opened this issue May 3, 2023 · 15 comments
Closed

Adding minute_file_sink_mt #2727

mmanoj opened this issue May 3, 2023 · 15 comments

Comments

@mmanoj
Copy link

mmanoj commented May 3, 2023

I created basic sink implementation as attached and driver code. However getting below errors. Please advice to fix it and if all fine we can merge with project.

===================
Errors
`logtest.cpp: In function ‘void setupLogging()’:
logtest.cpp:17:101: error: no matching function for call to ‘spdlog::sinks::minute_file_sinkstd::mutex::minute_file_sink(const char [13], const char [17], bool, int)’
17 | auto logger = spdlog::sinks::minute_file_sink_mt("basic_logger", "logs/min-log.txt",false,72);
| ^
In file included from logtest.cpp:10:
../include/spdlog/sinks/minute_file_sink.h:49:5: note: candidate: ‘spdlog::sinks::minute_file_sink<Mutex, FileNameCalc>::minute_file_sink(spdlog::filename_t, bool, uint16_t, const spdlog::file_event_handlers&) [with Mutex = std::mutex; FileNameCalc = spdlog::sinks::minute_filename_calculator; spdlog::filename_t = std::__cxx11::basic_string; uint16_t = short unsigned int]’
49 | minute_file_sink(
| ^~~~~~~~~~~~~~~~
../include/spdlog/sinks/minute_file_sink.h:50:109: note: no known conversion for argument 4 from ‘int’ to ‘const spdlog::file_event_handlers&’
50 | filename_t base_filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {})
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~

`

@mmanoj
Copy link
Author

mmanoj commented May 3, 2023

logtest.cpp.txt
minute_file_sink.h.txt

Driver code and sink files attached for reference.Appreciate your help

@mmanoj mmanoj mentioned this issue May 3, 2023
@tt4g
Copy link
Contributor

tt4g commented May 3, 2023

In setupLogging(), passing 74 4th arguments.

auto logger = spdlog::sinks::minute_file_sink_mt("basic_logger", "logs/min-log.txt",false,72);
                                                                                                                                             ^^

But declared file_event_handlers in constructor.

minute_file_sink(
        filename_t base_filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {})
        : base_filename_(std::move(base_filename))
        , file_helper_{event_handlers}
        , truncate_(truncate)
        , max_files_(max_files)
        , filenames_q_()

@mmanoj
Copy link
Author

mmanoj commented May 4, 2023

Hourly Logger define as below, I just modify to support minutes

template<typename Mutex, typename FileNameCalc = hourly_filename_calculator> class hourly_file_sink final : public base_sink<Mutex> { public: // create hourly file sink which rotates on given time hourly_file_sink( filename_t base_filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {}) : base_filename_(std::move(base_filename)) , file_helper_{event_handlers} , truncate_(truncate) , max_files_(max_files) , filenames_q_() {

This is how driver program define it.

//auto file_logger = spdlog::hourly_logger_mt("vxRadProbe", logfilename,false,72);//keep 3 days(72 Hrs)

Can you advice how it differed as above is working fine with hourly logger.

@tt4g
Copy link
Contributor

tt4g commented May 4, 2023

Look at the constructor arguments carefully.

@tt4g
Copy link
Contributor

tt4g commented May 4, 2023

It was hard to tell what you were doing wrong, but I think I might have figured it out.

In this line, you have made the mistake of calling the constructor with the intention of calling a factory function.

spdlog::sinks::minute_file_sink_mt("basic_logger", "logs/min-log.txt",false,72);

What is being called is the spdlog::sinks::minute_file_sink_mt constructor defined in the following code.

using minute_file_sink_mt = minute_file_sink<std::mutex>;
using minute_file_sink_st = minute_file_sink<details::null_mutex>;

} // namespace sinks

And what you wanted to call would be the following factory function spdlog::minute_logger_mt.

//
// factory functions
//
template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> minute_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false,
    uint16_t max_files = 0, const file_event_handlers &event_handlers = {})
{
    return Factory::template create<sinks::minute_file_sink_mt>(logger_name, filename, truncate, max_files, event_handlers);
}

They have different namespaces and symbol names.

@mmanoj
Copy link
Author

mmanoj commented May 4, 2023

@tt4g

Thanks for quick advice, It's fixed once i call the minute_logger_mt from driver code. You save my day!!!

Sample Log:
-rw-rw-r-- 1 manoj manoj 124 May 4 13:28 min-log_2023-05-04-13_28.txt

P.S:: Can we merge this code with project?

@tt4g
Copy link
Contributor

tt4g commented May 4, 2023

PR is welcome.

@mmanoj
Copy link
Author

mmanoj commented May 4, 2023

I will send shortly.

@mmanoj
Copy link
Author

mmanoj commented May 4, 2023

@tt4g
Please find the pull request.Thx for quick support
#2729

@tt4g
Copy link
Contributor

tt4g commented May 4, 2023

Unfortunately, I am not the maintainer of this repository and do not have merge privileges.

@mmanoj
Copy link
Author

mmanoj commented May 4, 2023

Hope some one will check and merge this PR

@gabime
Copy link
Owner

gabime commented Jul 3, 2023

@mmanoj Any news on this?

@mmanoj
Copy link
Author

mmanoj commented Jul 5, 2023

@gabime , Thank you for your patience, I was busy with some urgent project task. I will be start working on this next week.I will keep you posted.

@mmanoj
Copy link
Author

mmanoj commented Aug 10, 2023

@gabime
I need little help on test case execution.I send the details in pull request.
Can you help to understand how spdlog test framework work.I'm not able to run the test cases except example application under spdlog/tests/example directory.

for example how to run test_daily_logger.cpp

@tt4g
Copy link
Contributor

tt4g commented Aug 10, 2023

Run ctest command.

$ cmake .
$ ctest

# Run test target.
$ ctest spdlog-utests

Note the only spdlog test targets are spdlog-utests and spdlog-utests-ho (cannot only run test_daily_logger.cpp).

See also:

@gabime gabime closed this as completed Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants