Developer Journal: 30 April 2020

Posted on Thu 30 April 2020 in dev-journal

Today is going to be a short coding session. My only plan is to write a test for an issue that is not allowing the rotation of site logs to work correctly. The problem is just a permission issue as the user does not have permission to write to the folder. While I'm in there I'm also going to clean a few things up because seeing a log directory on a busy server would look obnoxious, imagine the output below if you had 10 sites running on a server..:

$ ls /var/log/uwsgi

app.conveyor.dev.log              app.conveyor.dev.log.1588156158
app.conveyor.dev.log.1570973320   app.conveyor.dev.log.1588156158
app.conveyor.dev.log.1570975544   app.conveyor.dev.log.1588158383
app.conveyor.dev.log.1570977769   app.conveyor.dev.log.1588160608
app.conveyor.dev.log.1570979994   app.conveyor.dev.log.1588162833
app.conveyor.dev.log.1570982220   app.conveyor.dev.log.1588165038
app.conveyor.dev.log.1570984445   app.conveyor.dev.log.1588167243
app.conveyor.dev.log.1570986669   app.conveyor.dev.log.1588169398
app.conveyor.dev.log.1570988904   app.conveyor.dev.log.1588171624
app.conveyor.dev.log.1570991139   app.conveyor.dev.log.1588173758
app.conveyor.dev.log.1570993374   app.conveyor.dev.log.1588175968
app.conveyor.dev.log.1570995609   app.conveyor.dev.log.1588178193
app.conveyor.dev.log.1570997844   app.conveyor.dev.log.1588180398
app.conveyor.dev.log.1571000080   app.conveyor.dev.log.1588182528
app.conveyor.dev.log.1571002314   app.conveyor.dev.log.1588184733
app.conveyor.dev.log.1571004549   app.conveyor.dev.log.1588186939
app.conveyor.dev.log.1571006779   app.conveyor.dev.log.1588188965
app.conveyor.dev.log.1571009014   app.conveyor.dev.log.1588190507
app.conveyor.dev.log.1571011249   app.conveyor.dev.log.1588271275
app.conveyor.dev.log.1571013479

First I am going to put each site in a subdirectory so the /var/log/uwsgi/ folder looks cleaner. There is already a test file to check the generated output against so I just need to update that file and this test that already exists will do the rest.

def test_format_site_ini_file(self):
    end_file = Provisioner.format_ini_file(site)
    with open(os.path.join(CURRENT_DIR, 'test_site_ini_file.txt'), 'r') as f:
        contents = f.read()
    self.assertEqual(contents, end_file)

To get the test to pass I just need to update a line in the template file to use the new subfolder structure, specifically this meant modifying the logto parameter to be /var/log/uwsgi/%n/%n.log