CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
156 lines
4.4 KiB
C++
156 lines
4.4 KiB
C++
//===- Logging.h - General logging class ------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// Provides ompTest-tailored logging, with log-levels and formatting/coloring.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_LOGGING_H
|
|
#define OPENMP_TOOLS_OMPTEST_INCLUDE_LOGGING_H
|
|
|
|
#include "OmptAssertEvent.h"
|
|
|
|
#include <iostream>
|
|
#include <map>
|
|
#include <mutex>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
namespace omptest {
|
|
namespace logging {
|
|
|
|
enum class Level : uint32_t {
|
|
// Levels (Note: DEBUG may already be reserved)
|
|
Diagnostic = 10,
|
|
Info = 20,
|
|
Warning = 30,
|
|
Error = 40,
|
|
Critical = 50,
|
|
|
|
// Types used for formatting options
|
|
Default,
|
|
ExpectedEvent,
|
|
ObservedEvent,
|
|
OffendingEvent,
|
|
|
|
// Suppress all prints
|
|
Silent = 0xFFFFFFFF
|
|
};
|
|
|
|
enum class FormatOption : uint32_t {
|
|
// General options
|
|
// Note: Bold is actually "BRIGHT" -- But it will be perceived as 'bold' font
|
|
// It is implicitly switching colors to the 'Light' variant
|
|
// Thus, it has -NO EFFECT- when already using a Light* color
|
|
None = 0,
|
|
Bold = 1,
|
|
Dim = 2,
|
|
Underlined = 4,
|
|
Blink = 5,
|
|
Inverted = 7,
|
|
Hidden = 8,
|
|
// Foreground colors
|
|
ColorDefault = 39,
|
|
ColorBlack = 30,
|
|
ColorRed = 31,
|
|
ColorGreen = 32,
|
|
ColorYellow = 33,
|
|
ColorBlue = 34,
|
|
ColorMagenta = 35,
|
|
ColorCyan = 36,
|
|
ColorLightGray = 37,
|
|
ColorDarkGray = 90,
|
|
ColorLightRed = 91,
|
|
ColorLightGreen = 92,
|
|
ColorLightYellow = 93,
|
|
ColorLightBlue = 94,
|
|
ColorLightMagenta = 95,
|
|
ColorLightCyan = 96,
|
|
ColorWhite = 97,
|
|
// Background colors
|
|
ColorBackgroundDefault = 49,
|
|
ColorBackgroundBlack = 40,
|
|
ColorBackgroundRed = 41,
|
|
ColorBackgroundGreen = 42,
|
|
ColorBackgroundYellow = 43,
|
|
ColorBackgroundBlue = 44,
|
|
ColorBackgroundMagenta = 45,
|
|
ColorBackgroundCyan = 46,
|
|
ColorBackgroundLightGray = 47,
|
|
ColorBackgroundDarkGray = 100,
|
|
ColorBackgroundLightRed = 101,
|
|
ColorBackgroundLightGreen = 102,
|
|
ColorBackgroundLightYellow = 103,
|
|
ColorBackgroundLightBlue = 104,
|
|
ColorBackgroundLightMagenta = 105,
|
|
ColorBackgroundLightCyan = 106,
|
|
ColorBackgroundWhite = 107
|
|
};
|
|
|
|
/// Returns a string representation of the given logging level.
|
|
const char *to_string(Level LogLevel);
|
|
|
|
/// Returns the format options as escaped sequence, for the given logging level
|
|
std::string getFormatSequence(Level LogLevel = Level::Default);
|
|
|
|
/// Format the given message with the provided option(s) and return it.
|
|
/// Here formatting is only concerning control sequences using <Esc> character
|
|
/// which can be obtained using '\e' (on console), '\033' or '\x1B'.
|
|
std::string format(const std::string &Message, FormatOption Option);
|
|
std::string format(const std::string &Message, std::set<FormatOption> Options);
|
|
|
|
class Logger {
|
|
public:
|
|
Logger(Level LogLevel = Level::Warning, std::ostream &OutStream = std::cerr,
|
|
bool FormatOutput = true);
|
|
~Logger();
|
|
|
|
/// Log the given message to the output.
|
|
void log(const std::string &Message, Level LogLevel) const;
|
|
|
|
/// Log a single event mismatch.
|
|
void logEventMismatch(const std::string &Message,
|
|
const omptest::OmptAssertEvent &OffendingEvent,
|
|
Level LogLevel = Level::Error) const;
|
|
|
|
/// Log an event-pair mismatch.
|
|
void logEventMismatch(const std::string &Message,
|
|
const omptest::OmptAssertEvent &ExpectedEvent,
|
|
const omptest::OmptAssertEvent &ObservedEvent,
|
|
Level LogLevel = Level::Error) const;
|
|
|
|
/// Set if output is being formatted (e.g. colored).
|
|
void setFormatOutput(bool Enabled);
|
|
|
|
/// Return the current (minimum) Logging Level.
|
|
Level getLoggingLevel() const;
|
|
|
|
/// Set the (minimum) Logging Level.
|
|
void setLoggingLevel(Level LogLevel);
|
|
|
|
private:
|
|
/// The minimum logging level that is considered by the logger instance.
|
|
Level LoggingLevel;
|
|
|
|
/// The output stream used by the logger instance.
|
|
std::ostream &OutStream;
|
|
|
|
/// Determine if log messages are formatted using control sequences.
|
|
bool FormatOutput;
|
|
|
|
/// Mutex to ensure serialized logging
|
|
mutable std::mutex LogMutex;
|
|
};
|
|
|
|
} // namespace logging
|
|
} // namespace omptest
|
|
|
|
#endif
|