@@ -17,8 +17,8 @@ import (
17
17
"github.com/golang-collections/go-datastructures/queue"
18
18
)
19
19
20
- // DefaulHttpListenerPort is used to set the URL where the logs will be sent by Logs API
21
- const DefaulHttpListenerPort = "1234"
20
+ // DefaultHttpListenerPort is used to set the URL where the logs will be sent by Logs API
21
+ const DefaultHttpListenerPort = "1234"
22
22
23
23
// LogsApiHttpListener is used to listen to the Logs API using HTTP
24
24
type LogsApiHttpListener struct {
@@ -36,12 +36,22 @@ func NewLogsApiHttpListener(lq *queue.Queue) (*LogsApiHttpListener, error) {
36
36
}, nil
37
37
}
38
38
39
+ func ListenOnAddress () string {
40
+ env_aws_local , ok := os .LookupEnv ("AWS_SAM_LOCAL" )
41
+ if ok && "true" == env_aws_local {
42
+ return ":" + DefaultHttpListenerPort
43
+ }
44
+
45
+ return "sandbox:" + DefaultHttpListenerPort
46
+ }
47
+
39
48
// Start initiates the server in a goroutine where the logs will be sent
40
49
func (s * LogsApiHttpListener ) Start () (bool , error ) {
41
- s .httpServer = & http.Server {Addr : ":" + DefaulHttpListenerPort }
50
+ address := ListenOnAddress ()
51
+ s .httpServer = & http.Server {Addr : address }
42
52
http .HandleFunc ("/" , s .http_handler )
43
53
go func () {
44
- logger .Infof ("Serving agent on %s" , ":" + DefaulHttpListenerPort )
54
+ logger .Infof ("Serving agent on %s" , address )
45
55
err := s .httpServer .ListenAndServe ()
46
56
if err != http .ErrServerClosed {
47
57
logger .Errorf ("Unexpected stop on Http Server: %v" , err )
@@ -138,7 +148,7 @@ func (a HttpAgent) Init(agentID string) error {
138
148
}
139
149
destination := logsapi.Destination {
140
150
Protocol : logsapi .HttpProto ,
141
- URI : logsapi .URI (fmt .Sprintf ("http://sandbox:%s" , DefaulHttpListenerPort )),
151
+ URI : logsapi .URI (fmt .Sprintf ("http://sandbox:%s" , DefaultHttpListenerPort )),
142
152
HttpMethod : logsapi .HttpPost ,
143
153
Encoding : logsapi .JSON ,
144
154
}
0 commit comments