Files
TheRock/compiler/amd-llvm/lldb/examples/summaries/cocoa/Logger.py
T
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

134 lines
3.4 KiB
Python

import sys
import os.path
import inspect
class NopLogger:
def __init__(self):
pass
def write(self, data):
pass
def flush(self):
pass
def close(self):
pass
class StdoutLogger:
def __init__(self):
pass
def write(self, data):
print(data)
def flush(self):
pass
def close(self):
pass
class FileLogger:
def __init__(self, name):
self.file = None
try:
name = os.path.abspath(name)
self.file = open(name, "a")
except:
try:
self.file = open("formatters.log", "a")
except:
pass
def write(self, data):
if self.file is not None:
print(data, file=self.file)
else:
print(data)
def flush(self):
if self.file is not None:
self.file.flush()
def close(self):
if self.file is not None:
self.file.close()
self.file = None
# to enable logging:
# define lldb.formatters.Logger._lldb_formatters_debug_level to any number greater than 0
# if you define it to any value greater than 1, the log will be automatically flushed after each write (slower but should make sure most of the stuff makes it to the log even if we crash)
# if you define it to any value greater than 2, the calling function's details will automatically be logged (even slower, but provides additional details)
# if you need the log to go to a file instead of on screen, define
# lldb.formatters.Logger._lldb_formatters_debug_filename to a valid
# filename
class Logger:
def __init__(self, autoflush=False, logcaller=False):
global _lldb_formatters_debug_level
global _lldb_formatters_debug_filename
self.autoflush = autoflush
want_log = False
try:
want_log = _lldb_formatters_debug_level > 0
except:
pass
if not (want_log):
self.impl = NopLogger()
return
want_file = False
try:
want_file = (
_lldb_formatters_debug_filename is not None
and _lldb_formatters_debug_filename != ""
and _lldb_formatters_debug_filename != 0
)
except:
pass
if want_file:
self.impl = FileLogger(_lldb_formatters_debug_filename)
else:
self.impl = StdoutLogger()
try:
self.autoflush = _lldb_formatters_debug_level > 1
except:
self.autoflush = autoflush
want_caller_info = False
try:
want_caller_info = _lldb_formatters_debug_level > 2
except:
pass
if want_caller_info:
self._log_caller()
def _log_caller(self):
caller = inspect.stack()[2]
try:
if caller is not None and len(caller) > 3:
self.write("Logging from function " + str(caller))
else:
self.write(
"Caller info not available - Required caller logging not possible"
)
finally:
del caller # needed per Python docs to avoid keeping objects alive longer than we care
def write(self, data):
self.impl.write(data)
if self.autoflush:
self.flush()
def __rshift__(self, data):
self.write(data)
def flush(self):
self.impl.flush()
def close(self):
self.impl.close()