Skip to content

Commit

Permalink
Change to logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
ktlim committed Oct 16, 2023
1 parent baf1951 commit 090141e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion python/s3daemon/s3daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import asyncio
import logging
import os
import time

Expand All @@ -40,6 +41,13 @@
access_key = os.environ["AWS_ACCESS_KEY_ID"]
secret_key = os.environ["AWS_SECRET_ACCESS_KEY"]

pylog_longLogFmt = "{levelname} {asctime} {name} - {message}"
if "S3DAEMON_LOG" in os.environ:
logging.basicConfig(filename=os.environ["S3DAEMON_LOG"], format=pylog_longLogFmt, style="{")
else:
logging.basicConfig(format=pylog_longLogFmt, style="{")
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)

async def handle_client(client, reader, writer):

Check failure on line 52 in python/s3daemon/s3daemon.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E302

expected 2 blank lines, found 1
"""Handle a client connection to the server socket.
Expand All @@ -63,7 +71,7 @@ async def handle_client(client, reader, writer):
writer.write(b"Success")
except Exception as e:
writer.write(bytes(repr(e), "UTF-8"))
print(start, time.time() - start, "sec")
log.info("%f %f sec", start, time.time() - start)


async def main():
Expand All @@ -81,6 +89,7 @@ async def client_cb(reader, writer):
await handle_client(client, reader, writer)

server = await asyncio.start_server(client_cb, "localhost", PORT)
log.info("Starting server")
async with server:
await server.serve_forever()

Expand Down

0 comments on commit 090141e

Please sign in to comment.