Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:50:55+00:00 2026-05-30T16:50:55+00:00

I wrote a small-ish Python script that handles nightly conversions and archiving of audio

  • 0

I wrote a small-ish Python script that handles nightly conversions and archiving of audio data. Since there have been some unexpected problems along the way (non-existing files, unreliable connection to the database server and so on…), I added Python’s own logging facility to keep track of any encountered problems.

The problem is, the log file is created wherever the script is run from (e.g. current working directory), so I have two logfiles, one in my homedir (which is used when the script is run by cron) and one in the script’s own directory (used when I debug it). I’d much prefer keeping the logfile and configuration file in the same directory as the script.

I’m loading logger’s configuration here:

logging.config.fileConfig(os.path.join(sys.path[0], 'logger.conf'))

…and here is the relevant portion of my logger.conf:

[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=fileFormatter
args=('echi_export.log', 'a',)

Absolute paths do work, I’m a bit reluctant to use them though.

In short, what is the proper way to configure file logging using Python’s logger module (especially the FileHandler)? Some real-world examples will suffice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:50:56+00:00Added an answer on May 30, 2026 at 4:50 pm

    So, apparently I can use Python expressions inside the configuration file:

    [handler_fileHandler]
      <snip>
    args=(os.path.join(sys.path[0],'echi_export.log'), 'a',)
    

    This results in the logfile being created in the same directory the script resides in.

    (os.path.dirname(__file__) resolves to /usr/lib/python2.7/logging/ on my system, which is probably where the logging module resides).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small .NET add in to excel 2007 that read data from
I have a large-ish file (4-5 GB compressed) of small messages that I wish
i wrote a small FQL script that returns the latest wallposts of my fanpage.
I wrote a small script to extract data from Oracle using Takusen: {-# LANGUAGE
I wrote a small PHP application several months ago that uses the WordPress XMLRPC
I wrote a small PHP application that I'd like to distribute. I'm looking for
We wrote a small Windows class library that implements extension methods for some standard
I wrote a small app that turns out to be using a lot of
I wrote a small program, that creates files at an interval of 1 minute.
I'd like to create a small script that basically does this: run program1.exe -->

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.