@@ -7,6 +7,8 @@ defmodule Opal.Application do
77
88 @ impl true
99 def start ( _type , _args ) do
10+ setup_file_logger ( )
11+
1012 children = [
1113 { Registry , keys: :unique , name: Opal.Registry } ,
1214 { Registry , keys: :duplicate , name: Opal.Events.Registry } ,
@@ -79,6 +81,36 @@ defmodule Opal.Application do
7981 |> String . to_atom ( )
8082 end
8183
84+ defp setup_file_logger do
85+ data_dir =
86+ Application . get_env ( :opal , :data_dir ) ||
87+ Opal.Config . default_data_dir ( )
88+
89+ logs_dir = Path . join ( Path . expand ( data_dir ) , "logs" )
90+ log_file = Path . join ( logs_dir , "server.log" )
91+
92+ with :ok <- File . mkdir_p ( logs_dir ) ,
93+ :ok <-
94+ :logger . add_handler ( :file_log , :logger_std_h , % {
95+ config: % {
96+ file: String . to_charlist ( log_file ) ,
97+ max_no_bytes: 5_000_000 ,
98+ max_no_files: 3
99+ } ,
100+ formatter:
101+ { :logger_formatter ,
102+ % {
103+ single_line: true ,
104+ template: [ :time , " [" , :level , "] " , :msg , "\n " ]
105+ } }
106+ } ) do
107+ :ok
108+ else
109+ { :error , reason } ->
110+ Logger . warning ( "Could not set up file logging: #{ inspect ( reason ) } " )
111+ end
112+ end
113+
82114 defp distribution_cookie do
83115 case Application . get_env ( :opal , :distribution_cookie , :random ) do
84116 :random -> generate_cookie ( )
0 commit comments