Paraphrasing the 2.9 Example: Add a handler to log info events to file section in the Logging chapter of the Kernel User's Guide:
1. Set log level (default: notice )
Globally: logger:set_primary_config/2
For certain modules only: logger:set_module_level/2
Accepted log levels (from least severe to most): debug , info , notice , warning , error , critical , alert , emergency
Note:
The default log level in the Erlang shell is notice , so if you leave it as is, but set a lower level (such as debug or info ) when adding a log handler in the next step, those level of logs will never get through.
Example:
logger:set_primary_config(level, debug).
2. Configure and add log handler
Specify the handler configuration map, for example:
3. Filter out logs below a certain level on Erlang shell
Following the examples above, all levels of logs will be printed. To restore the notice default, but still save every level of logs in the file), use logger:set_handler_config/3.
Work in progress: Log each process' events into their own logfile
This module documents my (partially successful) attempts; will revisit and expand on this section when time permits. My use case was that the FreeSWITCH phone server would spawn an Erlang process to handle the call, and so logging each of them into their own files made sense at the time.
1条答案
按热度按时间voase2hg1#
Paraphrasing the 2.9 Example: Add a handler to log info events to file section in the Logging chapter of the Kernel User's Guide:
1. Set log level (default:
notice
)logger:set_primary_config/2
logger:set_module_level/2
Accepted log levels (from least severe to most):
debug
,info
,notice
,warning
,error
,critical
,alert
,emergency
Note:
The default log level in the Erlang shell is
notice
, so if you leave it as is, but set a lower level (such asdebug
orinfo
) when adding a log handler in the next step, those level of logs will never get through.Example:
2. Configure and add log handler
Specify the handler configuration map, for example:
And add the handler:
logger_std_h
is the standard handler for Logger.3. Filter out logs below a certain level on Erlang shell
Following the examples above, all levels of logs will be printed. To restore the
notice
default, but still save every level of logs in the file), uselogger:set_handler_config/3
.Work in progress: Log each process' events into their own logfile
This module documents my (partially successful) attempts; will revisit and expand on this section when time permits. My use case was that the FreeSWITCH phone server would spawn an Erlang process to handle the call, and so logging each of them into their own files made sense at the time.