Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions swanlab/log/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ class Consoler(__consoler_class(), LeverCtl):
# 只有第一次输入时为None
__previous_message = None

def __init__(self):
init_status = True

def __init__(self, *args, **kwargs):
# 根据环境进行不同的初始化
if in_notebook():
super().__init__()
else:
super().__init__(sys.stdout.buffer)
try:
if in_notebook():
super().__init__()
else:
super().__init__(sys.stdout.buffer)
except:
self.init_status = False
self.original_stdout = sys.stdout # 保存原始的 sys.stdout

def init(self, path, swanlog_level="debug"):
Expand All @@ -153,6 +158,10 @@ def init(self, path, swanlog_level="debug"):
os.makedirs(path)
# 日志文件路径
console_path = os.path.join(path, f"{self.now}.log")
# 如果日志系统初始化失败
if not self.init_status:
with open(console_path, "w", encoding="utf-8") as f:
f.write("Console Recoder Init Failed!")
# 日志文件
self.console = open(console_path, "a", encoding="utf-8")

Expand Down Expand Up @@ -238,7 +247,8 @@ def __init__(self):

def init(self, path):
self.consoler.init(path)
sys.stdout = self.consoler
if self.consoler.init_status:
sys.stdout = self.consoler

def reset(self):
"""重置输出为原本的样子"""
Expand Down
5 changes: 4 additions & 1 deletion vue/src/views/experiment/pages/log/LogPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const indexWidth = computed(() => {
if (l) {
index = lines.value[l - 1].index === '' ? lines.value[l - 2].index : lines.value[l - 1].index
}
if (!index) return '0px'
return 8 * index.length + 'px'
})

Expand Down Expand Up @@ -222,7 +223,9 @@ const computeRange = (e) => {
* 一般行高是 16px,基本不会出问题,所以目前只在初始化时计算,而没做另外的事件监听
*/
const computeLineHeight = () => {
const line_styles = window.getComputedStyle(document.querySelector('.log-line'))
const e = document.querySelector('.log-line')
if (!e) return 0
const line_styles = window.getComputedStyle(e)
lineHeight.value = parseFloat(line_styles.getPropertyValue('line-height'))
}

Expand Down