File tree 3 files changed +36
-2
lines changed
3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,13 @@ crystal src/cnf-testsuite.cr <testname>
47
47
48
48
---
49
49
50
+ ### Logging Parameters
51
+
52
+ - ** LOG_LEVEL** environment variable: sets minimal log level to display: error (default); info; debug.
53
+ - ** LOG_PATH** environment variable: if set - all logs would be appended to the file defined by that variable.
54
+
55
+ ---
56
+
50
57
### Common Example Commands
51
58
52
59
#### Building the executable
Original file line number Diff line number Diff line change @@ -258,6 +258,18 @@ describe "Utils" do
258
258
CNFManager .sample_cleanup(config_file: " sample-cnfs/sample-coredns-cnf" , verbose: true )
259
259
end
260
260
261
+ it " 'logger' should write logs to the file when LOG_PATH is set" , tags: [" logger" ] do
262
+ response_s = ` LOG_PATH=spec-test-testsuite.log ./cnf-testsuite test`
263
+ $? .success?.should be_true
264
+ (/ERROR -- cnf-testsuite: error test/ =~ response_s).should be_nil
265
+ File .exists?(" spec-test-testsuite.log" ).should be_true
266
+ (/ERROR -- cnf-testsuite: error test/ =~ File .read(" spec-test-testsuite.log" )).should_not be_nil
267
+ ensure
268
+ if File .exists?(" spec-test-testsuite.log" )
269
+ File .delete(" spec-test-testsuite.log" )
270
+ end
271
+ end
272
+
261
273
it " '#update_yml' should update the value for a key in a yml file" , tags: [" logger" ] do
262
274
begin
263
275
update_yml(" spec/fixtures/cnf-testsuite.yml" , " release_name" , " coredns --set worker-node='kind-control-plane'" )
Original file line number Diff line number Diff line change 82
82
83
83
# this first line necessary to make sure our custom formatter
84
84
# is used in the default error log line also
85
- Log .setup(Log ::Severity ::Error , Log :: IOBackend .new( formatter: log_formatter) )
86
- Log .setup(loglevel, Log :: IOBackend .new( formatter: log_formatter) )
85
+ Log .setup(Log ::Severity ::Error , log_backend )
86
+ Log .setup(loglevel, log_backend )
87
87
88
+ def log_backend
89
+ if ENV .has_key?(" LOGPATH" ) || ENV .has_key?(" LOG_PATH" )
90
+ log_file = ENV .has_key?(" LOGPATH" ) ? ENV [" LOGPATH" ] : ENV [" LOG_PATH" ]
91
+ else
92
+ log_file = " "
93
+ end
94
+
95
+ if log_file.empty?
96
+ backend = Log ::IOBackend .new(formatter: log_formatter)
97
+ else
98
+ log_io = File .open(log_file, " a" )
99
+ backend = Log ::IOBackend .new(io: log_io, formatter: log_formatter)
100
+ end
101
+ backend
102
+ end
88
103
89
104
def loglevel
90
105
levelstr = " " # default to unset
You can’t perform that action at this time.
0 commit comments