Giter Club home page Giter Club logo

Comments (6)

kraiz avatar kraiz commented on July 22, 2024 4

Maybe we're running into a problem because the current working dir differs when started via cron. Please change the FileHandler's filename to be absolute. Does this help?

Another try: switch to ConsoleHandler and pipe result into a file:

    ('0   0 1 * *', 'myapp.cron.my_scheduled_job', '>> /tmp/scheduled_job.log'),

Does this work?

from django-crontab.

kraiz avatar kraiz commented on July 22, 2024 2

Can you provide your Django & Python version with your (simplified) settings for CRONJOBS, LOGGING?

Additionally what happens when you run

$ python manage.py crontab show

and find the logging job's hashed id and run

$ python manage.py crontab run <id>

Does the logging work in this case?

from django-crontab.

kraiz avatar kraiz commented on July 22, 2024

Shouldn't be there a logger for app.tasks as well? Depending on how log propagation is configured, that may a reason. But sure, if it's working from the django shell...I try to check that soon.

from django-crontab.

washougal avatar washougal commented on July 22, 2024

Django: 1.9.4, Py: 2.7.11

In settings.py:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': 'mysite.log',
            'formatter': 'verbose'
        },
        'scraper_file' : {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': 'scraping.log',
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'django': {
            'handlers':['file'],
            'propagate': True,
            'level':'DEBUG',
        },
        'scraper': {
            'handlers': ['scraper_file'],
            'level':'DEBUG',
            'propagate': True,
        },
        'django_crontab': {
            'handlers': ['scraper_file'],
            'level':'DEBUG',
            'propagate': True,
        },

        'django_crontab.crontab': {
            'handlers': ['scraper_file'],
            'level':'DEBUG',
            'propagate': True,
        },
        'crontab': {
            'handlers': ['scraper_file'],
            'level':'DEBUG',
            'propagate': True,
        },
        'scraper.django_crontab.crontab': {
            'handlers': ['scraper_file'],
            'level':'DEBUG',
            'propagate': True,
        },
        'scraper.tasks': {
            'handlers': ['scraper_file'],
            'level':'DEBUG',
            'propagate': True,
        },
    }
}

When runnig python manage.py crontab show it returns:
Currently active jobs in crontab: d2cbb85ad5f39a8d633df70b63312728 -> ('0/8 * * * *', 'scraper.tasks.my_scheduled_job')

and running python manage.py crontab run d2cbb85ad5f39a8d633df70b63312728 both correctly runs the function, and logs correctly. However, when cron runs the function, I can see the results showing up in the database, but nothing is being logged.

from django-crontab.

reata avatar reata commented on July 22, 2024

I came into the same problem. After changing the FileHandler's filename to be absolute path, it all settled. Probably the working dir issue. Thanks.

from django-crontab.

kraiz avatar kraiz commented on July 22, 2024

Thanks for sharing @Ryan-ZJU. I added a faq entry about this. Hopefully this helps the next one :)

from django-crontab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.