Skip to content

Commit

Permalink
新增错误日志记录
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuefeng committed Apr 20, 2019
1 parent 6069371 commit 1e9a890
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
11 changes: 2 additions & 9 deletions cmds/shutdown.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
int main(object me, string arg)
{
if (wizardp(me))
{
shutdown(0);
return 1;
}
else
{
return 0;
}
shutdown(0);
return 1;
}
9 changes: 2 additions & 7 deletions cmds/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ int main(object me, string file)
{
object ob, env = environment(me);

if (!wizardp(me))
{
return 0;
}

if (!file)
{
return notify_fail("指令:update /文件路径/文件名\n例如:update /cmds/shutdown \n");
Expand All @@ -22,10 +17,10 @@ int main(object me, string file)

if (file == VOID_OB)
{
return notify_fail("你不能在 VOID_OB 里重新编译 VOID_OB。\n");
return notify_fail("你不能在 VOID_OB 里编译 VOID_OB。\n");
}

write("重新编译[" + file + "]:");
write("编译[" + file + "]:");

if (ob = find_object(file))
{
Expand Down
2 changes: 2 additions & 0 deletions include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

#define LOGIN_OB "/system/object/login_ob"
#define VOID_OB "/system/object/void_ob"

#define LOG_DIR "/log/"
33 changes: 33 additions & 0 deletions system/kernel/master.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,36 @@ string creator_file(string str)
{
return str;
}

void log_error(string file, string message)
{
write_file(LOG_DIR + "log_error", message);
}

void error_handler(mapping map, int flag)
{
object ob;
string str;

ob = this_interactive() || this_player();

if (flag)
str = "*Error caught\n";
else
str = "";

str += sprintf("\nError: %s\nProgram: %s\nObject: %O\nFile: %s - Line: %d\n[%s]\n",
map["error"], (map["program"] || "No program"),
(map["object"] || "No object"),
map["file"],
map["line"],
implode(map_array(map["trace"],
(
: sprintf("\n\tProgram: %s\n\tObject: %O \n\tFile: %s\n\tFunction : %s\n\tLine: %d\n", $1["program"], $1["object"], $1["file"], $1["function"], $1["line"])
:)),
"\n"));
write_file(LOG_DIR + "error_handler", str);

if (!flag && ob)
tell_object(ob, str);
}
2 changes: 0 additions & 2 deletions system/object/login_ob.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ int command_hook(string arg);
void logon()
{
write(read_file(WELCOME));
set_heart_beat(1);
enable_wizard();
enable_commands();
add_action("command_hook", "", 1);
move_object(VOID_OB);
Expand Down

0 comments on commit 1e9a890

Please sign in to comment.