23.2 配置错误记录器

1. 标准错误记录器

在启动Erlang时可以给系统提供一个启动参数

erl -boot start_clean

它会创建一个适合进行程序开发的环境,只提供一种简单的错误记录形式。(不带启动参数的erl命令就等于erl -boot start_clean)

erl -boot start_sasl

它会创建一个适合运行生产系统的环境。系统架构支持(System Architecture Support Libraries,简称SASL)将负责错误记录和过载保护等工作

2. 无配置SASL

当我们不带配置文件启动SASL时会发生下面这些事:

PS C:\CodeProjects\ErlangProjects\erlang_learning\src\ets>  erl -boot start_sasl

=PROGRESS REPORT==== 11-Sep-2024::23:05:08 ===
          supervisor: {local,sasl_safe_sup}
             started: [{pid,<0.61.0>},
                       {id,alarm_handler},
                       {mfargs,{alarm_handler,start_link,[]}},
                       {restart_type,permanent},
                       {shutdown,2000},
                       {child_type,worker}]

=PROGRESS REPORT==== 11-Sep-2024::23:05:08 ===
          supervisor: {local,sasl_sup}
             started: [{pid,<0.60.0>},
                       {id,sasl_safe_sup},
                       {mfargs,
                           {supervisor,start_link,
                               [{local,sasl_safe_sup},sasl,safe]}},
                       {restart_type,permanent},
                       {shutdown,infinity},
                       {child_type,supervisor}]

=PROGRESS REPORT==== 11-Sep-2024::23:05:08 ===
          supervisor: {local,sasl_sup}
             started: [{pid,<0.62.0>},
                       {id,release_handler},
                       {mfargs,{release_handler,start_link,[]}},
                       {restart_type,permanent},
                       {shutdown,2000},
                       {child_type,worker}]

=PROGRESS REPORT==== 11-Sep-2024::23:05:08 ===
         application: sasl
          started_at: nonode@nohost
Eshell V9.3  (abort with ^G)

现在调用error_logger里的某个方法来报告一个错误

1> error_logger:error_msg("there is an error~n"). 

=ERROR REPORT==== 11-Sep-2024::23:08:15 ===
there is an error
ok

请注意,错误是在Erlang shell里报告的。错误的报告位置由错误记录器配置决定

控制记录内容

错误记录器会生成多种报告类型:

  • 监控器报告
    这些报告会在OTP监控器启动或停止被监控进程时生成
  • 进度报告
    这些报告会在OTP监控器启动或停止时生成
  • 崩溃报告
    如果某个被OTP行为启动的进程因为normal或shutdown以外的原因终止,这些报告就会生成

上述三种报告会自动生成,无需我们做任何事情
我们可以通过 编写配置文件的方式,配置错误记录器时可以选择只保存错误,丢弃其他所有类型的条目。现在,编写配置文件elog1.config来配置错误记录器
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/03c9c95f66f74dbaaef2eece34176b67.png =x180

%%由于我这里文件后缀不是config导致到不到所以报错,这个文件的后缀.config不能改变
PS C:\CodeProjects\ErlangProjects\erlang_learning\src\.cfg> erl -boot start_sasl -config erlog
{"could not start kernel pid",application_controller,"error in config file \"./erlog.config\" (none): configuration file not found"}
could not start kernel pid (application_controller) (error in config file "./erlog.config" (none): configuration file not found)
%%这里将文件后缀更改后就没报错了
PS C:\CodeProjects\ErlangProjects\erlang_learning\src\.cfg> erl -boot start_sasl -config erlog
Eshell V9.3  (abort with ^G)

如果用这个配置文件启动系统,就只会得到错误报告,不会有进度和其他报告。所有这些错
误报告只会出现在shell里

PS C:\CodeProjects\ErlangProjects\erlang_learning\src\.cfg> erl -boot start_sasl -config erlog
Eshell V9.3  (abort with ^G)
1> error_logger:error_msg("there is an error~n").
ok
=ERROR REPORT==== 11-Sep-2024::23:26:16 ===
there is an error
2>
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值