Browse Source

Log what config file got loaded, refactor a bit

Andy Baugh 11 tháng trước cách đây
mục cha
commit
e67e024609
2 tập tin đã thay đổi với 15 bổ sung và 8 xóa
  1. 3 3
      lib/TCMS.pm
  2. 12 5
      lib/Trog/Config.pm

+ 3 - 3
lib/TCMS.pm

@@ -77,6 +77,9 @@ sub _app {
     # Build the routing table
     state( $conf, $data, %aliases );
 
+    # Setup logging
+    log_init();
+
     $conf //= Trog::Config::get();
     $data //= Trog::Data->new($conf);
     my %routes = %{ _routes($data) };
@@ -86,9 +89,6 @@ sub _app {
     # This should eventually be pre-filled from DB.
     my %etags;
 
-    # Setup logging
-    log_init();
-
     my $requestid = Trog::Utils::uuid();
     Trog::Log::uuid($requestid);
 

+ 12 - 5
lib/Trog/Config.pm

@@ -4,7 +4,10 @@ use strict;
 use warnings;
 use feature qw{state};
 
+use FindBin::libs;
+
 use Config::Simple;
+use Trog::Log ();
 
 =head1 Trog::Config
 
@@ -17,14 +20,18 @@ Memoized, so you will need to HUP the children on config changes.
 
 =cut
 
-our $home_cfg = "config/main.cfg";
+our $home_cfg = "main.cfg";
+our $default  = "default.cfg";
 
 sub get {
     state $cf;
-    return $cf                           if $cf;
-    $cf = Config::Simple->new($home_cfg) if -f $home_cfg;
-    return $cf                           if $cf;
-    $cf = Config::Simple->new('config/default.cfg');
+    return $cf if $cf;
+    foreach my $cfg2try ($home_cfg, $default) {
+        next unless -f "config/$cfg2try";
+        $cf = Config::Simple->new("config/$cfg2try");
+        Trog::Log::INFO("Loaded config file: $home_cfg");
+        last;
+    }
     return $cf;
 }