blob: 420d059a4c0e1d6beeed0d4916fed7533ab20c15 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <lib/syslog/cpp/macros.h>
#include <lib/zx/time.h>
// Print a log message every |logging_interval| units of time.
// Users should periodically call |LogIfRequired|. Once |logging_interval|
// has passed since class creation, a log message will be printed. Log
// messages will then continue to be printed every |logging_interval|.
class PeriodicLogger {
PeriodicLogger(std::string operation, zx::duration logging_interval);
// Print a log message about the current operation if enough time has passed
// since the operation started / since the last log message.
void LogIfRequired();
const zx::time start_time_;
const std::string operation_;
const zx::duration logging_interval_;
bool message_printed_ = false;
zx::time last_log_time_;