mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-03 07:12:28 +00:00
Make QPDFLogger() private and provide create method
This commit is contained in:
parent
7049588bff
commit
0ad4e190ff
@ -31,7 +31,7 @@ class QPDFLogger
|
||||
{
|
||||
public:
|
||||
QPDF_DLL
|
||||
QPDFLogger();
|
||||
static std::shared_ptr<QPDFLogger> create();
|
||||
|
||||
// Return the default logger. In general, you should use the
|
||||
// default logger. You can also create your own loggers and use
|
||||
@ -152,6 +152,7 @@ class QPDFLogger
|
||||
void setOutputStreams(std::ostream* out_stream, std::ostream* err_stream);
|
||||
|
||||
private:
|
||||
QPDFLogger();
|
||||
std::shared_ptr<Pipeline>
|
||||
throwIfNull(std::shared_ptr<Pipeline>, bool null_okay);
|
||||
|
||||
|
@ -362,7 +362,7 @@ QPDF::setLogger(std::shared_ptr<QPDFLogger> l)
|
||||
void
|
||||
QPDF::setOutputStreams(std::ostream* out, std::ostream* err)
|
||||
{
|
||||
setLogger(std::make_shared<QPDFLogger>());
|
||||
setLogger(QPDFLogger::create());
|
||||
this->m->log->setOutputStreams(out, err);
|
||||
}
|
||||
|
||||
|
@ -460,7 +460,7 @@ QPDFJob::setLogger(std::shared_ptr<QPDFLogger> l)
|
||||
void
|
||||
QPDFJob::setOutputStreams(std::ostream* out, std::ostream* err)
|
||||
{
|
||||
setLogger(std::make_shared<QPDFLogger>());
|
||||
setLogger(QPDFLogger::create());
|
||||
this->m->log->setOutputStreams(out, err);
|
||||
}
|
||||
|
||||
|
@ -64,10 +64,16 @@ QPDFLogger::QPDFLogger() :
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<QPDFLogger>
|
||||
QPDFLogger::create()
|
||||
{
|
||||
return std::shared_ptr<QPDFLogger>(new QPDFLogger);
|
||||
}
|
||||
|
||||
std::shared_ptr<QPDFLogger>
|
||||
QPDFLogger::defaultLogger()
|
||||
{
|
||||
static auto l = std::make_shared<QPDFLogger>();
|
||||
static auto l = create();
|
||||
return l;
|
||||
}
|
||||
|
||||
|
@ -39,64 +39,64 @@ test2()
|
||||
{
|
||||
// First call saveToStandardOutput. Then use info, which then to
|
||||
// go stderr.
|
||||
QPDFLogger l;
|
||||
l.saveToStandardOutput(true);
|
||||
l.info(std::string("info to stderr\n"));
|
||||
*(l.getSave()) << "save to stdout\n";
|
||||
l.setInfo(nullptr);
|
||||
l.info("info still to stderr\n");
|
||||
l.setSave(nullptr, false);
|
||||
l.setInfo(nullptr);
|
||||
l.info("info back to stdout\n");
|
||||
auto l = QPDFLogger::create();
|
||||
l->saveToStandardOutput(true);
|
||||
l->info(std::string("info to stderr\n"));
|
||||
*(l->getSave()) << "save to stdout\n";
|
||||
l->setInfo(nullptr);
|
||||
l->info("info still to stderr\n");
|
||||
l->setSave(nullptr, false);
|
||||
l->setInfo(nullptr);
|
||||
l->info("info back to stdout\n");
|
||||
}
|
||||
|
||||
static void
|
||||
test3()
|
||||
{
|
||||
// Error/warning
|
||||
QPDFLogger l;
|
||||
auto l = QPDFLogger::create();
|
||||
|
||||
// Warning follows error when error is set explicitly.
|
||||
std::string errors;
|
||||
auto pl_error = std::make_shared<Pl_String>("errors", nullptr, errors);
|
||||
l.setError(pl_error);
|
||||
l.warn("warn follows error\n");
|
||||
l->setError(pl_error);
|
||||
l->warn("warn follows error\n");
|
||||
assert(errors == "warn follows error\n");
|
||||
l.error("error too\n");
|
||||
l->error("error too\n");
|
||||
assert(errors == "warn follows error\nerror too\n");
|
||||
|
||||
// Set warnings -- now they're separate
|
||||
std::string warnings;
|
||||
auto pl_warn = std::make_shared<Pl_String>("warnings", nullptr, warnings);
|
||||
l.setWarn(pl_warn);
|
||||
l.warn(std::string("warning now separate\n"));
|
||||
l.error(std::string("new error\n"));
|
||||
l->setWarn(pl_warn);
|
||||
l->warn(std::string("warning now separate\n"));
|
||||
l->error(std::string("new error\n"));
|
||||
assert(warnings == "warning now separate\n");
|
||||
assert(errors == "warn follows error\nerror too\nnew error\n");
|
||||
std::string errors2;
|
||||
pl_error = std::make_shared<Pl_String>("errors", nullptr, errors2);
|
||||
l.setError(pl_error);
|
||||
l.warn("new warning\n");
|
||||
l.error("another new error\n");
|
||||
l->setError(pl_error);
|
||||
l->warn("new warning\n");
|
||||
l->error("another new error\n");
|
||||
assert(warnings == "warning now separate\nnew warning\n");
|
||||
assert(errors == "warn follows error\nerror too\nnew error\n");
|
||||
assert(errors2 == "another new error\n");
|
||||
|
||||
// Restore warnings to default -- follows error again
|
||||
l.setWarn(nullptr);
|
||||
l.warn("warning 3\n");
|
||||
l.error("error 3\n");
|
||||
l->setWarn(nullptr);
|
||||
l->warn("warning 3\n");
|
||||
l->error("error 3\n");
|
||||
assert(warnings == "warning now separate\nnew warning\n");
|
||||
assert(errors == "warn follows error\nerror too\nnew error\n");
|
||||
assert(errors2 == "another new error\nwarning 3\nerror 3\n");
|
||||
|
||||
// Restore everything to default
|
||||
l.setInfo(nullptr);
|
||||
l.setWarn(nullptr);
|
||||
l.setError(nullptr);
|
||||
l.info("after reset, info to stdout\n");
|
||||
l.warn("after reset, warn to stderr\n");
|
||||
l.error("after reset, error to stderr\n");
|
||||
l->setInfo(nullptr);
|
||||
l->setWarn(nullptr);
|
||||
l->setError(nullptr);
|
||||
l->info("after reset, info to stdout\n");
|
||||
l->warn("after reset, warn to stderr\n");
|
||||
l->error("after reset, error to stderr\n");
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user