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

How do i wait an application when all consumed for log messages? #88

Closed
jhlee8804 opened this issue Apr 18, 2016 · 7 comments
Closed

How do i wait an application when all consumed for log messages? #88

jhlee8804 opened this issue Apr 18, 2016 · 7 comments
Labels

Comments

@jhlee8804
Copy link
Contributor

Hi,

I want to wait application until logger save all log messages,
How do i have??

Thanks.

@KjellKod
Copy link
Owner

Not sure I understand.

Do you want to wait with shutting down the application until the logger has written all log messages to disk?

That should happen automatically unless you kill your process with an "exit" call or similar.

Feel free to write a snippet of code to illustrate what the issue is.

@KjellKod
Copy link
Owner

KjellKod commented May 5, 2016

Closing this due to lack of response

@KjellKod KjellKod closed this as completed May 5, 2016
@jhlee8804
Copy link
Contributor Author

Sorry for delay and don't speak english well.
Your speaking is correct and follow link is too.
#91

Here is my code.

namespace {
static std::once_flag g_initLogger;
static std::unique_ptr<g3::LogWorker> g_logger;
static std::unique_ptr<g3::FileSinkHandle> g_loggerHandle;
} // namespace

void InitializeLogging(const std::string& logPrefix, const FilePath& logDir, bool timed) {
  std::call_once(g_initLogger, [&]{
    if (!DirectoryExists(logDir))
      CreateDirectory(logDir);

    std::string logPath = SysWideToNativeMB(logDir.AsUTF16Unsafe());
    g_logger = g3::LogWorker::createLogWorker();
    g_loggerHandle = g_logger->addDefaultLogger(logPrefix, logPath, timed);
    g3::initializeLogging(g_logger.get());
  });
}

bool IsLoggerEnabled() {
  return g3::internal::isLoggingInitialized();
}

void ShutdownLogging() {
  g3::internal::shutDownLogging();
  g_logger.reset();
}

and used them

BOOL MFCSample::InitInstance() {
  // ....
  InitializeLogging(L"MFCSample", "some_path", true);
}

int MFCSample::ExitInstance() {
  ShutdownLogging();
  return CWinAppEx::ExitInstance();
}

@KjellKod
Copy link
Owner

Thanks jhlee8804, this will be useful I hope for #91

@KjellKod
Copy link
Owner

I will add your example to the Wiki I think if that's OK with you?

@KjellKod
Copy link
Owner

FYI:

The g_logger.reset() is the only thing you need to do when shutting down.

Internally the destructor will call g3::internal::shutDownLogging();

@jhlee8804
Copy link
Contributor Author

OK, I will try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants