Skip to content

Commit a88c8e1

Browse files
Model logs
1 parent 0e61ea0 commit a88c8e1

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

kratos.gid/kratos.tcl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ proc Kratos::InitGlobalVariables {dir} {
148148
set Kratos::kratos_private(allow_logs) 1
149149
# git hash of the problemtype
150150
set Kratos::kratos_private(problemtype_git_hash) 0
151+
# Place were the logs will be placed
152+
set Kratos::kratos_private(model_log_folder) ""
151153

152154
# Variable to store the Kratos menu items
153155
set kratos_private(MenuItems) [dict create]
@@ -222,6 +224,8 @@ proc Kratos::Event_LoadModelSPD { filespd } {
222224
set old_doc [gid_groups_conds::open_XML_file_gzip $filespd]
223225
set old_root [$old_doc documentElement]
224226
set old_versionData [$old_root @version]
227+
set version_data [dict create model_version $old_versionData ]
228+
Kratos::Log "Load model -> [write::tcl2json $version_data]"
225229

226230
# Compare the version number
227231
if { [package vcompare $versionPT $old_versionData] != 0 } {
@@ -252,6 +256,8 @@ proc Kratos::Event_LoadModelSPD { filespd } {
252256

253257
# Open the tree
254258
spdAux::OpenTree
259+
260+
after 500 {set ::Kratos::kratos_private(model_log_folder) [file join [GiD_Info Project ModelName].gid Logs]}
255261
}
256262
}
257263

@@ -262,6 +268,9 @@ proc Kratos::Event_EndProblemtype { } {
262268
GiD_UnRegisterEvents PROBLEMTYPE Kratos
263269
}
264270
if {[array exists ::Kratos::kratos_private]} {
271+
# Close the log and moves them to the folder
272+
Kratos::FlushLog
273+
265274
# Restore GiD variables that were modified by kratos and must be restored (maybe mesher)
266275
Kratos::RestoreVariables
267276

@@ -506,7 +515,9 @@ proc Kratos::Event_SaveModelSPD { filespd } {
506515
apps::ExecuteOnCurrentApp AfterSaveModel $filespd
507516

508517
# Log it
518+
set Kratos::kratos_private(model_log_folder) [file join [GiD_Info Project ModelName].gid Logs]
509519
Kratos::Log "Save model $filespd"
520+
510521
}
511522

512523

kratos.gid/scripts/Logs.tcl

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ proc Kratos::InitLog { } {
3535
proc Kratos::Log {msg} {
3636
variable kratos_private
3737

38-
if {! $Kratos::kratos_private(allow_logs)} {return ""}
38+
if {[info exists kratos_private(Log)] && $Kratos::kratos_private(allow_logs) > 0} {
3939

40-
if {[info exists kratos_private(Log)]} {
41-
lappend kratos_private(Log) "*~* [clock format [clock seconds] -format {%Z %Y-%m-%d %H:%M:%S }] | $msg"
40+
if {[info exists kratos_private(Log)]} {
41+
lappend kratos_private(Log) "*~* [clock format [clock seconds] -format {%Z %Y-%m-%d %H:%M:%S }] | $msg"
4242

43-
# One of the triggers is to flush if we've stored more than 5
44-
if {[llength $kratos_private(Log)] > 5} {
45-
Kratos::FlushLog
43+
# One of the triggers is to flush if we've stored more than 5
44+
if {[llength $kratos_private(Log)] > 5} {
45+
Kratos::FlushLog
46+
}
4647
}
4748
}
4849
}
@@ -51,6 +52,7 @@ proc Kratos::FlushLog { } {
5152
variable kratos_private
5253

5354
if {[info exists kratos_private(Log)]} {
55+
# only disturb the disk if we have something new to write
5456
if {[llength $kratos_private(Log)] > 0} {
5557
set logpath [Kratos::GetLogFilePath]
5658

@@ -66,14 +68,18 @@ proc Kratos::FlushLog { } {
6668
}
6769

6870
set kratos_private(Log) [list ]
71+
# Move it to the model, so the user can see and store to get support
72+
# Keep the original to keep centralized data to send to the servers
73+
if {$Kratos::kratos_private(model_log_folder) ne ""} {
74+
Kratos::MoveLogsToFolder $Kratos::kratos_private(model_log_folder) 0
75+
}
6976
}
7077
}
7178

7279
}
7380

7481
proc Kratos::AutoFlush {} {
7582
if {! $Kratos::kratos_private(allow_logs)} {return ""}
76-
Kratos::FlushLog
7783
after 5000 {Kratos::AutoFlush}
7884
}
7985

@@ -88,3 +94,10 @@ if { [GiD_Set SaveGidDefaults] } {
8894
Kratos::InitLog
8995
}
9096

97+
proc Kratos::MoveLogsToFolder {folder {flush_log 1}} {
98+
99+
if {! $Kratos::kratos_private(allow_logs)} {return ""}
100+
if {$flush_log} {FlushLog}
101+
if {![file exists $folder]} {file mkdir $folder}
102+
file copy -force [Kratos::GetLogFilePath] $folder
103+
}

kratos.gid/scripts/Utils.tcl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,11 @@ proc Kratos::LogInitialData { } {
196196
Kratos::GetProblemtypeGitTag
197197

198198
set initial_data [dict create]
199-
dict set initial_data GiD_version [GiD_Info gidversion]
199+
dict set initial_data gid_version [GiD_Info gidversion]
200200
dict set initial_data problemtype_git_hash $Kratos::kratos_private(problemtype_git_hash)
201201
dict set initial_data problemtype_version $Kratos::kratos_private(Version)
202202
dict set initial_data executable_version $Kratos::kratos_private(exec_version)
203203
dict set initial_data current_platform $::tcl_platform(platform)
204-
dict set initial_data gid_version [GiD_Info gidversion]
205204

206205
Kratos::Log [write::tcl2json $initial_data]
207206
}

0 commit comments

Comments
 (0)