File tree Expand file tree Collapse file tree 2 files changed +61
-1
lines changed
ansible/files/home/packages/webhook/lib/deployer Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 17
17
require "json"
18
18
require "openssl"
19
19
require_relative "error"
20
+ require_relative "logger"
20
21
require_relative "payload"
21
22
require_relative "response"
22
23
@@ -94,7 +95,8 @@ def process_payload!(payload)
94
95
def deploy ( payload )
95
96
Thread . new do
96
97
# TODO: call rake tasks for sign packages.
97
- # TODO: write down the errors into log files.
98
+ rescue => e
99
+ Logger . log ( "error.log" , e . message )
98
100
end
99
101
end
100
102
end
Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2018 Kouhei Sutou <[email protected] >
2
+ # Copyright (C) 2024 Takuya Kodama <[email protected] >
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+
17
+ require "pathname"
18
+
19
+ module Deployer
20
+ class Logger
21
+ LOG_DIR = "log" . freeze
22
+
23
+ class << self
24
+ def log ( base_name , object )
25
+ new ( base_name ) . log ( object )
26
+ end
27
+ end
28
+
29
+ def initialize ( base_name )
30
+ @log_dir = prepare_log_dir
31
+ @base_name = base_name
32
+ @log_path = log_dir + base_name
33
+ end
34
+
35
+ def log ( object )
36
+ begin
37
+ File . open ( @log_path , "w" ) do |log |
38
+ if object . is_a? ( String )
39
+ log . puts ( object )
40
+ else
41
+ PP . pp ( object , log )
42
+ end
43
+ end
44
+ rescue SystemCallError
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def prepare_log_dir
51
+ log_dir = Pathname . new ( LOG_DIR )
52
+ return log_dir if log_dir . directory?
53
+
54
+ Pathname . mkdir ( LOG_DIR )
55
+ log_dir
56
+ end
57
+ end
58
+ end
You can’t perform that action at this time.
0 commit comments