@@ -10,6 +10,7 @@ import (
1010)
1111
1212type recordOptions struct {
13+ packageAlias string
1314 packagePath bool
1415 packageName bool
1516 structName bool
@@ -71,30 +72,41 @@ func PackagePath(b bool) recordOption {
7172 }
7273}
7374
75+ func Package (alias string ) recordOption {
76+ return func (opts * recordOptions ) {
77+ opts .packageAlias = alias
78+ }
79+ }
80+
7481var _ Caller = call {}
7582
7683type call struct {
7784 function uintptr
7885 file string
7986 line int
87+ opts []recordOption
8088}
8189
82- func Call (depth int ) (c call ) {
90+ func Call (depth int , opts ... recordOption ) (c call ) {
8391 c .function , c .file , c .line , _ = runtime .Caller (depth + 1 )
8492
93+ c .opts = opts
94+
8595 return c
8696}
8797
8898func (c call ) Record (opts ... recordOption ) string {
8999 optionsHolder := recordOptions {
90100 packagePath : true ,
101+ packageAlias : "" ,
91102 packageName : true ,
92103 structName : true ,
93104 functionName : true ,
94105 fileName : true ,
95106 line : true ,
96107 lambdas : true ,
97108 }
109+
98110 for _ , opt := range opts {
99111 if opt != nil {
100112 opt (& optionsHolder )
@@ -151,14 +163,22 @@ func buildRecordString(
151163) string {
152164 buffer := xstring .Buffer ()
153165 defer buffer .Free ()
154- if optionsHolder .packagePath {
155- buffer .WriteString (fnDetails .pkgPath )
156- }
157- if optionsHolder .packageName {
158- if buffer .Len () > 0 {
159- buffer .WriteByte ('/' )
166+ if optionsHolder .packageAlias != "" {
167+ buffer .WriteString (optionsHolder .packageAlias )
168+ } else {
169+ if optionsHolder .packagePath {
170+ if optionsHolder .packageAlias != "" {
171+ buffer .WriteString (optionsHolder .packageAlias )
172+ } else {
173+ buffer .WriteString (fnDetails .pkgPath )
174+ }
175+ }
176+ if optionsHolder .packageName {
177+ if buffer .Len () > 0 {
178+ buffer .WriteByte ('/' )
179+ }
180+ buffer .WriteString (fnDetails .pkgName )
160181 }
161- buffer .WriteString (fnDetails .pkgName )
162182 }
163183 if optionsHolder .structName && len (fnDetails .structName ) > 0 {
164184 if buffer .Len () > 0 {
@@ -198,7 +218,7 @@ func buildRecordString(
198218}
199219
200220func (c call ) String () string {
201- return c .Record (Lambda (false ), FileName (false ))
221+ return c .Record (append ( c . opts , Lambda (false ), FileName (false )) ... )
202222}
203223
204224func Record (depth int , opts ... recordOption ) string {
0 commit comments