debugtrace 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -3
- data/CHANGELOG_ja.md +24 -0
- data/README.md +44 -55
- data/README_ja.md +50 -59
- data/examples/debugtrace.yml +2 -3
- data/examples/readme-example.rb +5 -5
- data/lib/debugtrace/config.rb +49 -51
- data/lib/debugtrace/location.rb +33 -0
- data/lib/debugtrace/log_buffer.rb +1 -1
- data/lib/debugtrace/version.rb +1 -2
- data/lib/debugtrace.rb +28 -48
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 329e4c78cb0dd2a7778ec83d17c6b8b6a98bddcb27360322fa757d9c0779fd04
|
4
|
+
data.tar.gz: f1b7c56f4c029320a869c71e84babbf521f1b43dae89be907bca1a8e00f0dda5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72de200654893939ec841d1c70ba56be2f028b2afed076fbc649ccdc07b67a8a71705719e97e7bd5d3379143c43be6f4ec00c6c3f9e5308dec6132ff5a963957
|
7
|
+
data.tar.gz: 1159e8da5fc15885699615004d0ef361317f748281c7e90b284119adf64dcc6835578959cae095aed2640997ddb4be226437ca2049e5041c0911e2096dc5e970
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
|
-
##
|
1
|
+
## 1.1.1 - July 1, 2025
|
2
2
|
|
3
|
-
|
3
|
+
### Bug fixes
|
4
|
+
* Fixed a bug that caused exceptions to be thrown by the `enter`, `leave` and `print` methods depending on the conditions.
|
4
5
|
|
5
|
-
-
|
6
|
+
## 1.1.0 - May 25, 2025
|
7
|
+
|
8
|
+
### Bug fixes
|
9
|
+
|
10
|
+
* Fixed a bug where line breaks were not inserted between elements when outputting `Array`, `Hash`, and `Set` using the print method.
|
11
|
+
|
12
|
+
### Specification changes
|
13
|
+
|
14
|
+
* Changed the following keyword argument names for the `print` method, and also changed the property names of the same names in `debugtrace.yml`.
|
15
|
+
* `output_size_limit` ← `collection_limit`
|
16
|
+
* `output_length_limit` ← `string_limit` and `bytes_limit` _(Unified)_
|
17
|
+
|
18
|
+
## 1.0.1 - May 19, 2025
|
19
|
+
|
20
|
+
Fixed a bug that caused an error if the environment variable `DEBUGTRACE_CONFIG` was not set.
|
21
|
+
|
22
|
+
## 1.0.0 - May 18, 2025
|
23
|
+
|
24
|
+
This is the initial release.
|
data/CHANGELOG_ja.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
## 1.1.1 - 2025/7/1
|
2
|
+
|
3
|
+
#### バグ修正
|
4
|
+
* 条件によって`enter`, `leave`, `print`メソッドで例外がスローされるバグを修正。
|
5
|
+
|
6
|
+
## 1.1.0 - 2025/5/25
|
7
|
+
|
8
|
+
#### バグ修正
|
9
|
+
|
10
|
+
* `print`メソッドで`Array`, `Hash`および`Set`を出力する場合に要素間での改行が行われないバグの修正。
|
11
|
+
|
12
|
+
#### 仕様変更
|
13
|
+
|
14
|
+
* `print`メソッドの以下のキーワード引数名を変更、また`debugtrace.yml`の同名のプロパティ名も変更
|
15
|
+
* `output_size_limit` ← `collection_limit`
|
16
|
+
* `output_length_limit` ← `string_limit` および `bytes_limit` _(統一)_
|
17
|
+
|
18
|
+
## 1.0.1 - 2025/5/19
|
19
|
+
|
20
|
+
環境変数 `DEBUGTRACE_CONFIG` が設定されていない場合にエラーが発生するバグを修正
|
21
|
+
|
22
|
+
## 1.0.0 - 2025/5/18
|
23
|
+
|
24
|
+
最初のリリース
|
data/README.md
CHANGED
@@ -63,47 +63,46 @@ def func2
|
|
63
63
|
Contact.new(1, 'Akane' , 'Apple', Date.new(1991, 2, 3)),
|
64
64
|
Contact.new(2, 'Yukari', 'Apple', Date.new(1992, 3, 4))
|
65
65
|
]
|
66
|
-
DebugTrace.
|
67
|
-
DebugTrace.leave
|
66
|
+
DebugTrace.leave(contacts)
|
68
67
|
end
|
69
68
|
|
70
69
|
def func1
|
71
70
|
DebugTrace.enter
|
72
71
|
DebugTrace.print('Hello, World!')
|
73
|
-
func2
|
74
|
-
DebugTrace.leave
|
72
|
+
contacts = func2
|
73
|
+
DebugTrace.leave(contacts)
|
75
74
|
end
|
76
75
|
|
77
76
|
func1
|
78
77
|
```
|
79
78
|
|
80
79
|
```log
|
81
|
-
2025-
|
82
|
-
2025-
|
83
|
-
2025-
|
84
|
-
2025-
|
85
|
-
2025-
|
86
|
-
2025-
|
87
|
-
2025-
|
88
|
-
2025-
|
89
|
-
2025-
|
90
|
-
2025-
|
91
|
-
2025-
|
92
|
-
2025-
|
93
|
-
2025-
|
94
|
-
2025-
|
95
|
-
2025-
|
96
|
-
2025-
|
97
|
-
2025-
|
98
|
-
2025-
|
99
|
-
2025-
|
100
|
-
2025-
|
101
|
-
2025-
|
102
|
-
2025-
|
103
|
-
2025-
|
104
|
-
2025-
|
105
|
-
2025-
|
106
|
-
2025-
|
80
|
+
2025-07-01 19:12:34.756+09:00 DebugTrace-rb 1.1.1 on Ruby 3.4.4
|
81
|
+
2025-07-01 19:12:34.756+09:00 config file: <No config file>
|
82
|
+
2025-07-01 19:12:34.756+09:00 logger: StdErrLogger
|
83
|
+
2025-07-01 19:12:34.756+09:00
|
84
|
+
2025-07-01 19:12:34.756+09:00 ______________________________ #72 ______________________________
|
85
|
+
2025-07-01 19:12:34.756+09:00
|
86
|
+
2025-07-01 19:12:34.756+09:00 Enter func1 (readme-example.rb:29) <- <main> (readme-example.rb:35)
|
87
|
+
2025-07-01 19:12:34.756+09:00 | Hello, World! (readme-example.rb:30)
|
88
|
+
2025-07-01 19:12:34.756+09:00 | Enter func2 (readme-example.rb:20) <- func1 (readme-example.rb:31)
|
89
|
+
2025-07-01 19:12:34.756+09:00 | | Enter initialize (readme-example.rb:10) <- new (readme-example.rb:22)
|
90
|
+
2025-07-01 19:12:34.756+09:00 | | Leave initialize (readme-example.rb:15) duration: 0.012 ms
|
91
|
+
2025-07-01 19:12:34.756+09:00 | |
|
92
|
+
2025-07-01 19:12:34.756+09:00 | | Enter initialize (readme-example.rb:10) <- new (readme-example.rb:23)
|
93
|
+
2025-07-01 19:12:34.756+09:00 | | Leave initialize (readme-example.rb:15) duration: 0.008 ms
|
94
|
+
2025-07-01 19:12:34.756+09:00 | Leave func2 (readme-example.rb:25) duration: 0.236 ms
|
95
|
+
2025-07-01 19:12:34.757+09:00 Leave func1 (readme-example.rb:32) duration: 0.365 ms
|
96
|
+
2025-07-01 19:12:34.757+09:00
|
97
|
+
2025-07-01 19:12:34.757+09:00 contacts = [
|
98
|
+
2025-07-01 19:12:34.757+09:00 Contact{
|
99
|
+
2025-07-01 19:12:34.757+09:00 @id: 1, @firstName: 'Akane', @lastName: 'Apple', @birthday: 1991-02-03
|
100
|
+
2025-07-01 19:12:34.757+09:00 },
|
101
|
+
2025-07-01 19:12:34.757+09:00 Contact{
|
102
|
+
2025-07-01 19:12:34.757+09:00 @id: 2, @firstName: 'Yukari', @lastName: 'Apple',
|
103
|
+
2025-07-01 19:12:34.757+09:00 @birthday: 1992-03-04
|
104
|
+
2025-07-01 19:12:34.757+09:00 }
|
105
|
+
2025-07-01 19:12:34.757+09:00 ] (readme-example.rb:36)
|
107
106
|
```
|
108
107
|
|
109
108
|
### 4. List of methods
|
@@ -140,8 +139,8 @@ DebugTrace module has the following methods.
|
|
140
139
|
<small><i>The following arguments can be specified in debugtrace.yml (argument specification takes precedence)</i></small><br>
|
141
140
|
<code>minimum_output_size</code>: The minimum number of elements to print for <code>Array</code>, <code>Hash</code> and <code>Set</code><br>
|
142
141
|
<code>minimum_output_length</code>: The minimum length to print the length of the string<br>
|
143
|
-
<code>
|
144
|
-
<code>
|
142
|
+
<code>output_size_limit</code>: The limit on the number of elements output for <code>Map</code>, <code>Hash</code> and <code>Set</code><br>
|
143
|
+
<code>output_length_limit</code>: The limit on the number of characters that can be output from a string<br>
|
145
144
|
<code>reflection_limit</code>: The limit of reflection nesting<br>
|
146
145
|
</td>
|
147
146
|
<td>the argument value if it is specified, otherwise <code>nil</code></td>
|
@@ -527,44 +526,30 @@ You can specify the following properties in debugtrace.yml.
|
|
527
526
|
</td>
|
528
527
|
</tr>
|
529
528
|
<tr>
|
530
|
-
<td><code>
|
529
|
+
<td><code>output_size_limit</code></td>
|
531
530
|
<td>
|
532
531
|
The limit on the number of elements output for <code>Array</code>, <code>Hash</code>, and <code>Set</code><br>
|
533
532
|
<small><b>Example:</b></small>
|
534
533
|
<ul>
|
535
|
-
<code>
|
534
|
+
<code>output_size_limit: 64</code>
|
536
535
|
</ul>
|
537
536
|
<small><b>Default Value:</b></small>
|
538
537
|
<ul>
|
539
|
-
<code>
|
538
|
+
<code>output_size_limit: 128</code>
|
540
539
|
</ul>
|
541
540
|
</td>
|
542
541
|
</tr>
|
543
542
|
<tr>
|
544
|
-
<td><code>
|
543
|
+
<td><code>output_length_limit</code></td>
|
545
544
|
<td>
|
546
|
-
|
545
|
+
The limit on the number of characters that can be output from a string<br>
|
547
546
|
<small><b>Example:</b></small>
|
548
547
|
<ul>
|
549
|
-
<code>
|
548
|
+
<code>output_length_limit: 64</code>
|
550
549
|
</ul>
|
551
550
|
<small><b>Default Value:</b></small>
|
552
551
|
<ul>
|
553
|
-
<code>
|
554
|
-
</ul>
|
555
|
-
</td>
|
556
|
-
</tr>
|
557
|
-
<tr>
|
558
|
-
<td><code>bytes_limit</code></td>
|
559
|
-
<td>
|
560
|
-
The limit on the number of characters to be output a string as a byte array<br>
|
561
|
-
<small><b>Example:</b></small>
|
562
|
-
<ul>
|
563
|
-
<code>bytes_limit: 64</code>
|
564
|
-
</ul>
|
565
|
-
<small><b>Default Value:</b></small>
|
566
|
-
<ul>
|
567
|
-
<code>bytes_limit: 256</code>
|
552
|
+
<code>output_length_limit: 256</code>
|
568
553
|
</ul>
|
569
554
|
</td>
|
570
555
|
</tr>
|
@@ -584,9 +569,13 @@ You can specify the following properties in debugtrace.yml.
|
|
584
569
|
</tr>
|
585
570
|
</table>
|
586
571
|
|
587
|
-
### 6.
|
572
|
+
### 6. CHANGELOG
|
573
|
+
|
574
|
+
[CHANGELOG](CHANGELOG.md)
|
575
|
+
|
576
|
+
### 7. License
|
588
577
|
|
589
578
|
[MIT License(MIT)](LICENSE.txt)
|
590
579
|
|
591
|
-
_
|
580
|
+
_© 2025 Masato Kokubo_
|
592
581
|
|
data/README_ja.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
**DebugTrace-rb** は、Rubyのデバッグ時にトレースログを出力するライブラリで、 Ruby 3.1.0以降で利用できます。
|
6
6
|
メソッドの開始と終了箇所に`DebugTrace.enter`および`DebugTrace.leave` を埋め込む事で、開発中のRubyプログラムの実行状況を出力する事ができます。
|
7
7
|
|
8
|
-
|
8
|
+
### 1. 特徴
|
9
9
|
|
10
10
|
* 呼び出し元のメソッド名、ソースファイル名および行番号を自動的に出力。
|
11
11
|
* メソッドやオブジェクトのネストで、ログを自動的にインデント 。
|
@@ -13,7 +13,7 @@
|
|
13
13
|
* リフレクションを使用してオブジェクト内容の出力が可能。
|
14
14
|
* `debugtrace.yml`ファイルの設定で、出力内容のカスタマイズが可能。
|
15
15
|
|
16
|
-
|
16
|
+
### 2. インストール
|
17
17
|
|
18
18
|
次のコマンドを実行して、gemをインストールし、アプリケーションのGemfileに追加します。
|
19
19
|
|
@@ -27,7 +27,7 @@ $ bundle add debugtrace
|
|
27
27
|
$ gem install debugtrace
|
28
28
|
```
|
29
29
|
|
30
|
-
|
30
|
+
### 3. 使用方法
|
31
31
|
|
32
32
|
デバッグ対象および関連するメソッドに対して以下を行います。
|
33
33
|
|
@@ -40,7 +40,8 @@ $ gem install debugtrace
|
|
40
40
|
```ruby
|
41
41
|
# frozen_string_literal: true
|
42
42
|
# readme-example.rb
|
43
|
-
require 'debugtrace'
|
43
|
+
#require 'debugtrace'
|
44
|
+
require_relative '../lib/debugtrace'
|
44
45
|
|
45
46
|
class Contact
|
46
47
|
attr_reader :id, :firstName, :lastName, :birthday
|
@@ -61,47 +62,47 @@ def func2
|
|
61
62
|
Contact.new(1, 'Akane' , 'Apple', Date.new(1991, 2, 3)),
|
62
63
|
Contact.new(2, 'Yukari', 'Apple', Date.new(1992, 3, 4))
|
63
64
|
]
|
64
|
-
DebugTrace.
|
65
|
-
DebugTrace.leave
|
65
|
+
DebugTrace.leave(contacts)
|
66
66
|
end
|
67
67
|
|
68
68
|
def func1
|
69
69
|
DebugTrace.enter
|
70
70
|
DebugTrace.print('Hello, World!')
|
71
|
-
func2
|
72
|
-
DebugTrace.leave
|
71
|
+
contacts = func2
|
72
|
+
DebugTrace.leave(contacts)
|
73
73
|
end
|
74
74
|
|
75
|
-
func1
|
75
|
+
contacts = func1
|
76
|
+
DebugTrace.print('contacts', contacts)
|
76
77
|
```
|
77
78
|
|
78
79
|
```log
|
79
|
-
2025-
|
80
|
-
2025-
|
81
|
-
2025-
|
82
|
-
2025-
|
83
|
-
2025-
|
84
|
-
2025-
|
85
|
-
2025-
|
86
|
-
2025-
|
87
|
-
2025-
|
88
|
-
2025-
|
89
|
-
2025-
|
90
|
-
2025-
|
91
|
-
2025-
|
92
|
-
2025-
|
93
|
-
2025-
|
94
|
-
2025-
|
95
|
-
2025-
|
96
|
-
2025-
|
97
|
-
2025-
|
98
|
-
2025-
|
99
|
-
2025-
|
100
|
-
2025-
|
101
|
-
2025-
|
102
|
-
2025-
|
103
|
-
2025-
|
104
|
-
2025-
|
80
|
+
2025-07-01 19:12:34.756+09:00 DebugTrace-rb 1.1.1 on Ruby 3.4.4
|
81
|
+
2025-07-01 19:12:34.756+09:00 config file: <No config file>
|
82
|
+
2025-07-01 19:12:34.756+09:00 logger: StdErrLogger
|
83
|
+
2025-07-01 19:12:34.756+09:00
|
84
|
+
2025-07-01 19:12:34.756+09:00 ______________________________ #72 ______________________________
|
85
|
+
2025-07-01 19:12:34.756+09:00
|
86
|
+
2025-07-01 19:12:34.756+09:00 Enter func1 (readme-example.rb:29) <- <main> (readme-example.rb:35)
|
87
|
+
2025-07-01 19:12:34.756+09:00 | Hello, World! (readme-example.rb:30)
|
88
|
+
2025-07-01 19:12:34.756+09:00 | Enter func2 (readme-example.rb:20) <- func1 (readme-example.rb:31)
|
89
|
+
2025-07-01 19:12:34.756+09:00 | | Enter initialize (readme-example.rb:10) <- new (readme-example.rb:22)
|
90
|
+
2025-07-01 19:12:34.756+09:00 | | Leave initialize (readme-example.rb:15) duration: 0.012 ms
|
91
|
+
2025-07-01 19:12:34.756+09:00 | |
|
92
|
+
2025-07-01 19:12:34.756+09:00 | | Enter initialize (readme-example.rb:10) <- new (readme-example.rb:23)
|
93
|
+
2025-07-01 19:12:34.756+09:00 | | Leave initialize (readme-example.rb:15) duration: 0.008 ms
|
94
|
+
2025-07-01 19:12:34.756+09:00 | Leave func2 (readme-example.rb:25) duration: 0.236 ms
|
95
|
+
2025-07-01 19:12:34.757+09:00 Leave func1 (readme-example.rb:32) duration: 0.365 ms
|
96
|
+
2025-07-01 19:12:34.757+09:00
|
97
|
+
2025-07-01 19:12:34.757+09:00 contacts = [
|
98
|
+
2025-07-01 19:12:34.757+09:00 Contact{
|
99
|
+
2025-07-01 19:12:34.757+09:00 @id: 1, @firstName: 'Akane', @lastName: 'Apple', @birthday: 1991-02-03
|
100
|
+
2025-07-01 19:12:34.757+09:00 },
|
101
|
+
2025-07-01 19:12:34.757+09:00 Contact{
|
102
|
+
2025-07-01 19:12:34.757+09:00 @id: 2, @firstName: 'Yukari', @lastName: 'Apple',
|
103
|
+
2025-07-01 19:12:34.757+09:00 @birthday: 1992-03-04
|
104
|
+
2025-07-01 19:12:34.757+09:00 }
|
105
|
+
2025-07-01 19:12:34.757+09:00 ] (readme-example.rb:36)
|
105
106
|
```
|
106
107
|
|
107
108
|
### 4. メソッド一覧
|
@@ -138,8 +139,8 @@ DebugTraceモジュールには以下のメソッドがあります。
|
|
138
139
|
<small><i>以降の引数は、debugtrace.ymlで指定可能 (引数指定が優先)</i></small><br>
|
139
140
|
<code>minimum_output_size</code>: <code>Array</code>, <code>Hash</code>および<code>Set</code>の要素数を出力する最小要素数<br>
|
140
141
|
<code>minimum_output_length</code>: 文字列の長さを出力する最小の長さ<br>
|
141
|
-
<code>
|
142
|
-
<code>
|
142
|
+
<code>output_size_limit</code>: <code>Array</code>, <code>Hash</code>および<code>Set</code>の要素の出力数の制限値<br>
|
143
|
+
<code>output_length_limit</code>: 文字列の出力文字数の制限値<br>
|
143
144
|
<code>reflection_limit</code>: リフレクションのネスト数の制限値<br>
|
144
145
|
</td>
|
145
146
|
<td>値の指定があれば引数値、なければ<code>nil</code></td>
|
@@ -525,44 +526,30 @@ debugtrace.ymlには以下のプロパティを指定できます。
|
|
525
526
|
</td>
|
526
527
|
</tr>
|
527
528
|
<tr>
|
528
|
-
<td><code>
|
529
|
+
<td><code>output_size_limit</code></td>
|
529
530
|
<td>
|
530
531
|
Array</code>, <code>Hash</code>および<code>Set</code>の要素の出力数の制限値<br>
|
531
532
|
<small><b>設定例:</b></small>
|
532
533
|
<ul>
|
533
|
-
<code>
|
534
|
+
<code>output_size_limit: 64</code>
|
534
535
|
</ul>
|
535
536
|
<small><b>初期値:</b></small>
|
536
537
|
<ul>
|
537
|
-
<code>
|
538
|
+
<code>output_size_limit: 128</code>
|
538
539
|
</ul>
|
539
540
|
</td>
|
540
541
|
</tr>
|
541
542
|
<tr>
|
542
|
-
<td><code>
|
543
|
+
<td><code>output_length_limit</code></td>
|
543
544
|
<td>
|
544
545
|
文字列の出力文字数の制限値<br>
|
545
546
|
<small><b>設定例:</b></small>
|
546
547
|
<ul>
|
547
|
-
<code>
|
548
|
+
<code>output_length_limit: 64</code>
|
548
549
|
</ul>
|
549
550
|
<small><b>初期値:</b></small>
|
550
551
|
<ul>
|
551
|
-
<code>
|
552
|
-
</ul>
|
553
|
-
</td>
|
554
|
-
</tr>
|
555
|
-
<tr>
|
556
|
-
<td><code>bytes_limit</code></td>
|
557
|
-
<td>
|
558
|
-
文字列をバイト配列として出力する場合のの出力数の制限値<br>
|
559
|
-
<small><b>設定例:</b></small>
|
560
|
-
<ul>
|
561
|
-
<code>bytes_limit: 64</code>
|
562
|
-
</ul>
|
563
|
-
<small><b>初期値:</b></small>
|
564
|
-
<ul>
|
565
|
-
<code>bytes_limit: 256</code>
|
552
|
+
<code>output_length_limit: 256</code>
|
566
553
|
</ul>
|
567
554
|
</td>
|
568
555
|
</tr>
|
@@ -582,9 +569,13 @@ debugtrace.ymlには以下のプロパティを指定できます。
|
|
582
569
|
</tr>
|
583
570
|
</table>
|
584
571
|
|
585
|
-
### 6.
|
572
|
+
### 6. 修正履歴
|
573
|
+
|
574
|
+
[修正履歴](CHANGELOG_ja.md)
|
575
|
+
|
576
|
+
### 7. ライセンス
|
586
577
|
|
587
578
|
[MIT ライセンス(MIT)](LICENSE.txt)
|
588
579
|
|
589
|
-
_
|
580
|
+
_© 2025 Masato Kokubo_
|
590
581
|
|
data/examples/debugtrace.yml
CHANGED
data/examples/readme-example.rb
CHANGED
@@ -22,15 +22,15 @@ def func2
|
|
22
22
|
Contact.new(1, 'Akane' , 'Apple', Date.new(1991, 2, 3)),
|
23
23
|
Contact.new(2, 'Yukari', 'Apple', Date.new(1992, 3, 4))
|
24
24
|
]
|
25
|
-
DebugTrace.
|
26
|
-
DebugTrace.leave
|
25
|
+
DebugTrace.leave(contacts)
|
27
26
|
end
|
28
27
|
|
29
28
|
def func1
|
30
29
|
DebugTrace.enter
|
31
30
|
DebugTrace.print('Hello, World!')
|
32
|
-
func2
|
33
|
-
DebugTrace.leave
|
31
|
+
contacts = func2
|
32
|
+
DebugTrace.leave(contacts)
|
34
33
|
end
|
35
34
|
|
36
|
-
func1
|
35
|
+
contacts = func1
|
36
|
+
DebugTrace.print('contacts', contacts)
|
data/lib/debugtrace/config.rb
CHANGED
@@ -8,31 +8,30 @@ require_relative 'common'
|
|
8
8
|
class Config
|
9
9
|
attr_reader :config_path
|
10
10
|
attr_reader :config
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
attr_reader :reflection_limit
|
11
|
+
attr_accessor :logger_name
|
12
|
+
attr_accessor :log_path
|
13
|
+
attr_accessor :rubylogger_format
|
14
|
+
attr_accessor :log_datetime_format
|
15
|
+
attr_accessor :enter_format
|
16
|
+
attr_accessor :leave_format
|
17
|
+
attr_accessor :thread_boundary_format
|
18
|
+
attr_accessor :maximum_indents
|
19
|
+
attr_accessor :indent_string
|
20
|
+
attr_accessor :data_indent_string
|
21
|
+
attr_accessor :limit_string
|
22
|
+
attr_accessor :circular_reference_string
|
23
|
+
attr_accessor :varname_value_separator
|
24
|
+
attr_accessor :key_value_separator
|
25
|
+
attr_accessor :print_suffix_format
|
26
|
+
attr_accessor :size_format
|
27
|
+
attr_accessor :minimum_output_size
|
28
|
+
attr_accessor :length_format
|
29
|
+
attr_accessor :minimum_output_length
|
30
|
+
attr_accessor :data_output_width
|
31
|
+
attr_accessor :bytes_count_in_line
|
32
|
+
attr_accessor :output_size_limit
|
33
|
+
attr_accessor :output_length_limit
|
34
|
+
attr_accessor :reflection_limit
|
36
35
|
|
37
36
|
# Initializes with a yml file in the config_path.
|
38
37
|
#
|
@@ -45,32 +44,31 @@ class Config
|
|
45
44
|
@config_path = '<No config file>'
|
46
45
|
@config = nil
|
47
46
|
end
|
48
|
-
@logger_name = get_value 'logger'
|
49
|
-
@log_path = get_value 'log_path'
|
50
|
-
@rubylogger_format = get_value 'rubylogger_format'
|
51
|
-
@log_datetime_format = get_value 'log_datetime_format'
|
52
|
-
@enabled = get_value 'enabled'
|
53
|
-
@enter_format = get_value 'enter_format'
|
54
|
-
@leave_format = get_value 'leave_format'
|
55
|
-
@thread_boundary_format = get_value 'thread_boundary_format'
|
56
|
-
@maximum_indents = get_value 'maximum_indents'
|
57
|
-
@indent_string = get_value 'indent_string'
|
58
|
-
@data_indent_string = get_value 'data_indent_string'
|
59
|
-
@limit_string = get_value 'limit_string'
|
60
|
-
@circular_reference_string = get_value 'circular_reference_string'
|
61
|
-
@varname_value_separator = get_value 'varname_value_separator'
|
62
|
-
@key_value_separator = get_value 'key_value_separator'
|
63
|
-
@print_suffix_format = get_value 'print_suffix_format'
|
64
|
-
@size_format = get_value 'size_format'
|
65
|
-
@minimum_output_size = get_value 'minimum_output_size'
|
66
|
-
@length_format = get_value 'length_format'
|
67
|
-
@minimum_output_length = get_value 'minimum_output_length'
|
68
|
-
@data_output_width = get_value 'data_output_width'
|
69
|
-
@bytes_count_in_line = get_value 'bytes_count_in_line'
|
70
|
-
@
|
71
|
-
@
|
72
|
-
@
|
73
|
-
@reflection_limit = get_value 'reflection_limit' , 4
|
47
|
+
@logger_name = get_value 'logger' , 'stderr'
|
48
|
+
@log_path = get_value 'log_path' , 'debugtrace.log'
|
49
|
+
@rubylogger_format = get_value 'rubylogger_format' , "%2$s %1$s %4$s\n"
|
50
|
+
@log_datetime_format = get_value 'log_datetime_format' , '%Y-%m-%d %H:%M:%S.%L%:z'
|
51
|
+
@enabled = get_value 'enabled' , true
|
52
|
+
@enter_format = get_value 'enter_format' , 'Enter %1$s (%2$s:%3$d) <- %4$s (%5$s:%6$d)'
|
53
|
+
@leave_format = get_value 'leave_format' , 'Leave %1$s (%2$s:%3$d) duration: %4$.3f ms'
|
54
|
+
@thread_boundary_format = get_value 'thread_boundary_format' , '______________________________ %1$s #%2$d ______________________________'
|
55
|
+
@maximum_indents = get_value 'maximum_indents' , 32
|
56
|
+
@indent_string = get_value 'indent_string' , '| '
|
57
|
+
@data_indent_string = get_value 'data_indent_string' , ' '
|
58
|
+
@limit_string = get_value 'limit_string' , '...'
|
59
|
+
@circular_reference_string = get_value 'circular_reference_string', '*** Circular Reference ***'
|
60
|
+
@varname_value_separator = get_value 'varname_value_separator' , ' = '
|
61
|
+
@key_value_separator = get_value 'key_value_separator' , ': '
|
62
|
+
@print_suffix_format = get_value 'print_suffix_format' , ' (%2$s:%3$d)'
|
63
|
+
@size_format = get_value 'size_format' , '(size:%d)'
|
64
|
+
@minimum_output_size = get_value 'minimum_output_size' , 256
|
65
|
+
@length_format = get_value 'length_format' , '(length:%d)'
|
66
|
+
@minimum_output_length = get_value 'minimum_output_length' , 256
|
67
|
+
@data_output_width = get_value 'data_output_width' , 70
|
68
|
+
@bytes_count_in_line = get_value 'bytes_count_in_line' , 16
|
69
|
+
@output_size_limit = get_value 'output_size_limit' , 128
|
70
|
+
@output_length_limit = get_value 'output_length_limit' , 256
|
71
|
+
@reflection_limit = get_value 'reflection_limit' , 4
|
74
72
|
end
|
75
73
|
|
76
74
|
# Returns true if logging is enabled, false otherwise.
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# location.rb
|
3
|
+
# (C) 2025 Masato Kokubo
|
4
|
+
|
5
|
+
# Contains source location information.
|
6
|
+
class Location
|
7
|
+
attr_reader :name
|
8
|
+
attr_reader :filename
|
9
|
+
attr_reader :lineno
|
10
|
+
|
11
|
+
# Initializes this object.
|
12
|
+
#
|
13
|
+
# @param caller_location [Thread::Backtrace::Location] the caller location
|
14
|
+
def initialize(caller_location)
|
15
|
+
if caller_location == nil
|
16
|
+
@name = 'unknown'
|
17
|
+
@filename = 'unknown'
|
18
|
+
@lineno = 0
|
19
|
+
else
|
20
|
+
@name = caller_location.base_label
|
21
|
+
path = caller_location.absolute_path || caller_location.path || 'unknown'
|
22
|
+
@filename = File.basename(path)
|
23
|
+
@lineno = caller_location.lineno
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns a string representation of this object.
|
28
|
+
#
|
29
|
+
# @return [String] A string representation of this object
|
30
|
+
def to_s()
|
31
|
+
return "(Location){name: #{@name}, filename: #{@filename}, lineno: #{@lineno}"
|
32
|
+
end
|
33
|
+
end
|
data/lib/debugtrace/version.rb
CHANGED
data/lib/debugtrace.rb
CHANGED
@@ -9,6 +9,7 @@ require 'date'
|
|
9
9
|
require_relative 'debugtrace/version'
|
10
10
|
require_relative 'debugtrace/common'
|
11
11
|
require_relative 'debugtrace/config'
|
12
|
+
require_relative 'debugtrace/location'
|
12
13
|
require_relative 'debugtrace/log_buffer'
|
13
14
|
require_relative 'debugtrace/loggers'
|
14
15
|
require_relative 'debugtrace/state'
|
@@ -86,32 +87,29 @@ module DebugTrace
|
|
86
87
|
# Contains options to pass to the print method.
|
87
88
|
class PrintOptions
|
88
89
|
attr_reader :reflection, :minimum_output_size, :minimum_output_length,
|
89
|
-
:
|
90
|
+
:output_size_limit, :output_length_limit, :reflection_limit
|
90
91
|
|
91
92
|
# Initializes this object.
|
92
93
|
#
|
93
94
|
# @param reflection [TrueClass, FalseClass] use reflection if true
|
94
95
|
# @param minimum_output_size [Integer] the minimum value to output the number of elements for Array and Hash (overrides debugtarace.yml value)
|
95
96
|
# @param minimum_output_length [Integer] the minimum value to output the length of String and byte array (overrides debugtarace.yml value)
|
96
|
-
# @param
|
97
|
-
# @param
|
98
|
-
# @param string_limit [Integer] the limit value of characters for string to output (overrides debugtarace.yml value)
|
97
|
+
# @param output_size_limit [Integer] Output limit of collection elements (overrides debugtarace.yml value)
|
98
|
+
# @param output_length_limit [Integer] the limit value of characters for string to output (overrides debugtarace.yml value)
|
99
99
|
# @param reflection_limit [Integer] reflection limits when using reflection (overrides debugtarace.yml value)
|
100
100
|
def initialize(
|
101
101
|
reflection,
|
102
102
|
minimum_output_size,
|
103
103
|
minimum_output_length,
|
104
|
-
|
105
|
-
|
106
|
-
string_limit,
|
104
|
+
output_size_limit,
|
105
|
+
output_length_limit,
|
107
106
|
reflection_limit
|
108
107
|
)
|
109
108
|
@reflection = reflection
|
110
109
|
@minimum_output_size = minimum_output_size == -1 ? DebugTrace.config.minimum_output_size : minimum_output_size
|
111
110
|
@minimum_output_length = minimum_output_length == -1 ? DebugTrace.config.minimum_output_length : minimum_output_length
|
112
|
-
@
|
113
|
-
@
|
114
|
-
@string_limit = string_limit == -1 ? DebugTrace.config.string_limit : string_limit
|
111
|
+
@output_size_limit = output_size_limit == -1 ? DebugTrace.config.output_size_limit : output_size_limit
|
112
|
+
@output_length_limit = output_length_limit == -1 ? DebugTrace.config.output_length_limit : output_length_limit
|
115
113
|
@reflection_limit = reflection_limit == -1 ? DebugTrace.config.reflection_limit : reflection_limit
|
116
114
|
end
|
117
115
|
end
|
@@ -228,7 +226,7 @@ module DebugTrace
|
|
228
226
|
|
229
227
|
count = 1
|
230
228
|
value.each_char do |char|
|
231
|
-
if count > print_options.
|
229
|
+
if count > print_options.output_length_limit
|
232
230
|
single_quote_buff.no_break_append(@@config.limit_string)
|
233
231
|
double_quote_buff.no_break_append(@@config.limit_string)
|
234
232
|
break
|
@@ -302,7 +300,7 @@ module DebugTrace
|
|
302
300
|
buff.line_feed
|
303
301
|
chars = ''
|
304
302
|
end
|
305
|
-
if count >= print_options.
|
303
|
+
if count >= print_options.output_length_limit
|
306
304
|
buff.no_break_append(@@config.limit_string)
|
307
305
|
break
|
308
306
|
end
|
@@ -414,11 +412,11 @@ module DebugTrace
|
|
414
412
|
close_char = ']'
|
415
413
|
|
416
414
|
if values.is_a?(Hash)
|
417
|
-
#
|
415
|
+
# Hash
|
418
416
|
open_char = '{'
|
419
417
|
close_char = '}'
|
420
418
|
elsif values.is_a?(Set)
|
421
|
-
#
|
419
|
+
# Set
|
422
420
|
open_char = 'Set['
|
423
421
|
close_char = ']'
|
424
422
|
end
|
@@ -461,7 +459,7 @@ module DebugTrace
|
|
461
459
|
values.each do |element|
|
462
460
|
buff.no_break_append(', ') if index > 0
|
463
461
|
|
464
|
-
if index >= print_options.
|
462
|
+
if index >= print_options.output_size_limit
|
465
463
|
buff.append(@@config.limit_string)
|
466
464
|
break
|
467
465
|
end
|
@@ -540,15 +538,12 @@ module DebugTrace
|
|
540
538
|
# @option reflection [TrueClass, FalseClass] use reflection if true
|
541
539
|
# @option minimum_output_size [Integer] the minimum value to output the number of elements for Array and Hash (overrides debugtarace.yml value)
|
542
540
|
# @option minimum_output_length [Integer] the minimum value to output the length of String and byte array (overrides debugtarace.yml value)
|
543
|
-
# @option
|
544
|
-
# @option
|
545
|
-
# @option string_limit [Integer] the limit value of characters for string to output (overrides debugtarace.yml value)
|
541
|
+
# @option output_size_limit [Integer] Output limit of collection elements (overrides debugtarace.yml value)
|
542
|
+
# @option output_length_limit [Integer] the limit value of characters for string to output (overrides debugtarace.yml value)
|
546
543
|
# @option reflection_limit [Integer] reflection limits when using reflection (overrides debugtarace.yml value)
|
547
544
|
def self.print(name, value = @@DO_NOT_OUTPUT,
|
548
|
-
reflection: false,
|
549
|
-
|
550
|
-
collection_limit: -1, bytes_limit: -1,
|
551
|
-
string_limit: -1, reflection_limit: -1)
|
545
|
+
reflection: false, minimum_output_size: -1, minimum_output_length: -1,
|
546
|
+
output_size_limit: -1, output_length_limit: -1, reflection_limit: -1)
|
552
547
|
@@thread_mutex.synchronize do
|
553
548
|
print_start
|
554
549
|
return value unless @@config.enabled?
|
@@ -565,22 +560,17 @@ module DebugTrace
|
|
565
560
|
else
|
566
561
|
# with value
|
567
562
|
print_options = PrintOptions.new(
|
568
|
-
reflection,
|
569
|
-
|
570
|
-
collection_limit, bytes_limit,
|
571
|
-
string_limit, reflection_limit
|
563
|
+
reflection, minimum_output_size, minimum_output_length,
|
564
|
+
output_size_limit, output_length_limit, reflection_limit
|
572
565
|
)
|
573
566
|
@@last_log_buff = to_string(name, value, print_options)
|
574
567
|
end
|
575
568
|
|
576
569
|
# append print suffix
|
577
|
-
location = caller_locations(3, 3)[0]
|
578
|
-
name = !location.nil? ? location.base_label : ''
|
579
|
-
filename = !location.nil? ? File.basename(location.absolute_path) : ''
|
580
|
-
lineno = !location.nil? ? location.lineno : 0
|
570
|
+
location = Location.new(caller_locations(3, 3)[0])
|
581
571
|
|
582
572
|
@@last_log_buff.no_break_append(
|
583
|
-
format(@@config.print_suffix_format, name, filename, lineno)
|
573
|
+
format(@@config.print_suffix_format, location.name, location.filename, location.lineno)
|
584
574
|
)
|
585
575
|
|
586
576
|
@@last_log_buff.line_feed
|
@@ -604,16 +594,8 @@ module DebugTrace
|
|
604
594
|
return unless @@config.enabled?
|
605
595
|
|
606
596
|
state = current_state
|
607
|
-
|
608
|
-
|
609
|
-
name = !location.nil? ? location.base_label : ''
|
610
|
-
filename = !location.nil? ? File.basename(location.absolute_path) : ''
|
611
|
-
lineno = !location.nil? ? location.lineno : 0
|
612
|
-
|
613
|
-
parent_location = caller_locations(4, 4)[0]
|
614
|
-
parent_name = !parent_location.nil? ? parent_location.base_label : ''
|
615
|
-
parent_filename = !parent_location.nil? ? File.basename(parent_location.absolute_path) : ''
|
616
|
-
parent_lineno = !parent_location.nil? ? parent_location.lineno : 0
|
597
|
+
location = Location.new(caller_locations(3, 3)[0])
|
598
|
+
parent_location = Location.new(caller_locations(4, 4)[0])
|
617
599
|
|
618
600
|
indent_string = get_indent_string(state.nest_level, 0)
|
619
601
|
if state.nest_level < state.previous_nest_level || @@last_log_buff.multi_lines?
|
@@ -622,7 +604,9 @@ module DebugTrace
|
|
622
604
|
|
623
605
|
@@last_log_buff = LogBuffer.new(@@config.data_output_width)
|
624
606
|
@@last_log_buff.no_break_append(
|
625
|
-
format(@@config.enter_format,
|
607
|
+
format(@@config.enter_format,
|
608
|
+
location.name, location.filename, location.lineno,
|
609
|
+
parent_location.name, parent_location.filename, parent_location.lineno)
|
626
610
|
)
|
627
611
|
@@last_log_buff.line_feed
|
628
612
|
@@logger.print(indent_string + @@last_log_buff.lines[0].log)
|
@@ -641,11 +625,7 @@ module DebugTrace
|
|
641
625
|
return return_value unless @@config.enabled?
|
642
626
|
|
643
627
|
state = current_state
|
644
|
-
|
645
|
-
location = caller_locations(3, 3)[0]
|
646
|
-
name = location.base_label
|
647
|
-
filename = File.basename(location.absolute_path)
|
648
|
-
lineno = location.lineno
|
628
|
+
location = Location.new(caller_locations(3, 3)[0])
|
649
629
|
|
650
630
|
if @@last_log_buff.multi_lines?
|
651
631
|
@@logger.print(get_indent_string(state.nest_level, 0)) # Empty Line
|
@@ -655,7 +635,7 @@ module DebugTrace
|
|
655
635
|
|
656
636
|
@@last_log_buff = LogBuffer.new(@@config.data_output_width)
|
657
637
|
@@last_log_buff.no_break_append(
|
658
|
-
format(@@config.leave_format, name, filename, lineno, time)
|
638
|
+
format(@@config.leave_format, location.name, location.filename, location.lineno, time)
|
659
639
|
)
|
660
640
|
@@last_log_buff.line_feed
|
661
641
|
@@logger.print(get_indent_string(state.nest_level, 0) + @@last_log_buff.lines[0].log)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debugtrace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masato Kokubo
|
@@ -20,6 +20,7 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- ".rubocop.yml"
|
22
22
|
- CHANGELOG.md
|
23
|
+
- CHANGELOG_ja.md
|
23
24
|
- LICENSE.txt
|
24
25
|
- README.md
|
25
26
|
- README_ja.md
|
@@ -29,6 +30,7 @@ files:
|
|
29
30
|
- lib/debugtrace.rb
|
30
31
|
- lib/debugtrace/common.rb
|
31
32
|
- lib/debugtrace/config.rb
|
33
|
+
- lib/debugtrace/location.rb
|
32
34
|
- lib/debugtrace/log_buffer.rb
|
33
35
|
- lib/debugtrace/loggers.rb
|
34
36
|
- lib/debugtrace/state.rb
|