xref: /aosp_15_r20/external/zlib/google/redact.h (revision 86ee64e75fa5f8bce2c8c356138035642429cd05)
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #ifndef THIRD_PARTY_ZLIB_GOOGLE_REDACT_H_
5 #define THIRD_PARTY_ZLIB_GOOGLE_REDACT_H_
6 
7 #include <ostream>
8 
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 
12 namespace zip {
13 
14 // Redacts file paths in log messages.
15 // Example:
16 // LOG(ERROR) << "Cannot open " << Redact(path);
17 class Redact {
18  public:
Redact(const base::FilePath & path)19   explicit Redact(const base::FilePath& path) : path_(path) {}
20 
21   friend std::ostream& operator<<(std::ostream& out, const Redact&& r) {
22     return LOG_IS_ON(INFO) ? out << "'" << r.path_ << "'" : out << "(redacted)";
23   }
24 
25  private:
26   const base::FilePath& path_;
27 };
28 
29 }  // namespace zip
30 
31 #endif  // THIRD_PARTY_ZLIB_GOOGLE_REDACT_H_
32