@@ -35,6 +35,7 @@ const (
3535
3636// Email is an instance of the email logger
3737type Email struct {
38+ enabled bool
3839 formatter Formatter
3940 formatFunc FormatFunc
4041 timestampFormat string
@@ -45,22 +46,21 @@ type Email struct {
4546 password string
4647 from string
4748 to []string
48- send bool
4949 rw sync.RWMutex
5050 once sync.Once
5151}
5252
5353// New returns a new instance of the email logger
5454func New (host string , port int , username string , password string , from string , to []string ) * Email {
5555 e := & Email {
56+ enabled : true ,
5657 timestampFormat : log .DefaultTimeFormat ,
5758 host : host ,
5859 port : port ,
5960 username : username ,
6061 password : password ,
6162 from : from ,
6263 to : to ,
63- send : true ,
6464 formatFunc : defaultFormatFunc ,
6565 }
6666 e .SetTemplate (defaultTemplate )
@@ -130,12 +130,12 @@ func (email *Email) SetEmailConfig(host string, port int, username string, passw
130130 email .formatter = email .formatFunc (email )
131131}
132132
133- // SetSend enables or disables the email handler sending emails
134- func (email * Email ) SetSend ( send bool ) {
133+ // SetEnabled enables or disables the email handler sending emails
134+ func (email * Email ) SetEnabled ( enabled bool ) {
135135 email .rw .Lock ()
136136 defer email .rw .Unlock ()
137137
138- email .send = send
138+ email .enabled = enabled
139139}
140140
141141func defaultFormatFunc (email * Email ) Formatter {
@@ -165,12 +165,18 @@ func defaultFormatFunc(email *Email) Formatter {
165165
166166// Log handles the log entry
167167func (email * Email ) Log (e log.Entry ) {
168- if ! email .send {
168+ email .rw .RLock ()
169+
170+ if ! email .enabled {
169171 return
170172 }
173+
174+ email .rw .RUnlock ()
175+
171176 email .once .Do (func () {
172177 email .formatter = email .formatFunc (email )
173178 })
179+
174180 var s gomail.SendCloser
175181 var err error
176182 var open bool
0 commit comments