Skip to content

Commit befe872

Browse files
committed
Add --log-file option to direct output to a file. Closes #63
1 parent 8edd548 commit befe872

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ When starting the proxy there are several optional arguments that can be set to
5151

5252
`--config-file` allows you to specify the location of a [configuration file](emailproxy.config) that the proxy should load. If this argument is not provided, the proxy will look for `emailproxy.config` in the same directory as the script itself.
5353

54+
`--log-file` allows you to specify the location of a file to send log output to. This option overrides the proxy's default behaviour, which varies by platform (see [`Log.initialise()`](https://github.com/simonrob/email-oauth2-proxy/search?q=staticmethod+initialise)).
55+
5456
`--debug` enables debug mode, printing more verbose output to the log as [discussed below](#troubleshooting). This argument is identical to enabling debug mode from the menu bar icon.
5557

5658
### Starting the proxy automatically
@@ -108,6 +110,8 @@ The [plugins branch](https://github.com/simonrob/email-oauth2-proxy/tree/plugins
108110
## Related projects and alternatives
109111
Michael Stepner has created a [Terraform configuration](https://github.com/michaelstepner/email-oauth2-proxy-aws) that helps run this proxy on a lightweight cloud server (AWS EC2). Philippe-Adrien Nousse has provided an [example Docker configuration](https://github.com/linka-cloud/email-oauth2-proxy/commit/67ca6b8fd0709d85480de2e3ea0af79439e6ba22) (though please note that the fork is otherwise outdated, and it is better to use this repository for the proxy script itself).
110112

113+
If you already use postfix, the [sasl-xoauth2](https://github.com/tarickb/sasl-xoauth2) plugin is probably a better solution than running this proxy.
114+
111115
[DavMail](http://davmail.sourceforge.net/) is an alternative that takes the same approach of providing a local IMAP/POP/SMTP server (and more) for Exchange/Office 365, though it does this by translating these protocols into Exchange API calls rather than proxying the connection. That approach is very useful in situations where server-side IMAP/POP/SMTP is not supported or enabled, or the full Exchange capabilities are needed, but it has limitations in terms of speed and the number of email messages that can be retrieved. This proxy was developed to work around these limitations for providers that do support IMAP/POP/SMTP natively.
112116

113117

emailproxy.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ class Log:
177177
_MACOS_USE_SYSLOG = not pyoslog.is_supported() if sys.platform == 'darwin' else False
178178

179179
@staticmethod
180-
def initialise():
180+
def initialise(log_file=None):
181181
Log._LOGGER = logging.getLogger(APP_NAME)
182-
if sys.platform == 'win32':
183-
handler = logging.FileHandler('%s/%s.log' % (os.path.dirname(os.path.realpath(__file__)), APP_SHORT_NAME))
182+
if log_file or sys.platform == 'win32':
183+
handler = logging.FileHandler(
184+
log_file if log_file else '%s/%s.log' % (os.path.dirname(os.path.realpath(__file__)), APP_SHORT_NAME))
184185
handler.setFormatter(logging.Formatter('%(asctime)s: %(message)s'))
185186
elif sys.platform == 'darwin':
186187
if Log._MACOS_USE_SYSLOG: # syslog prior to 10.12
@@ -1487,8 +1488,7 @@ def __init__(self, proxy_type, local_address, server_address, custom_configurati
14871488
def info_string(self):
14881489
return '%s server at %s:%d (%s) proxying %s:%d (%s)' % (
14891490
self.proxy_type, self.local_address[0], self.local_address[1],
1490-
'TLS' if self.ssl_connection else 'unsecured',
1491-
self.server_address[0], self.server_address[1],
1491+
'TLS' if self.ssl_connection else 'unsecured', self.server_address[0], self.server_address[1],
14921492
'STARTTLS' if self.custom_configuration['starttls'] else 'SSL/TLS')
14931493

14941494
def handle_accept(self):
@@ -1706,8 +1706,6 @@ class App:
17061706
"""Manage the menu bar icon, server loading, authorisation and notifications, and start the main proxy thread"""
17071707

17081708
def __init__(self):
1709-
Log.initialise()
1710-
17111709
global CONFIG_FILE_PATH
17121710
parser = argparse.ArgumentParser(description=APP_NAME)
17131711
parser.add_argument('--external-auth', action='store_true', help='handle authorisation via an external browser '
@@ -1722,9 +1720,15 @@ def __init__(self):
17221720
parser.add_argument('--config-file', default=None, help='the full path to the proxy\'s configuration file '
17231721
'(optional; default: `%s` in the same directory as the '
17241722
'proxy script)' % os.path.basename(CONFIG_FILE_PATH))
1723+
parser.add_argument('--log-file', default=None, help='the full path to a file where log output should be sent '
1724+
'(optional; default behaviour varies by platform, but see '
1725+
'Log.initialise() for details)')
17251726
parser.add_argument('--debug', action='store_true', help='enable debug mode, printing client<->proxy<->server '
17261727
'interaction to the system log')
1728+
17271729
self.args = parser.parse_args()
1730+
1731+
Log.initialise(self.args.log_file)
17281732
if self.args.debug:
17291733
Log.set_level(logging.DEBUG)
17301734

0 commit comments

Comments
 (0)