GithubHelp home page GithubHelp logo

IBMi python logging about ibmi-oss-docs HOT 5 CLOSED

sgonchigar avatar sgonchigar commented on August 27, 2024
IBMi python logging

from ibmi-oss-docs.

Comments (5)

kadler avatar kadler commented on August 27, 2024

Sorry for the noise, I was not paying close enough attention to where this was opened against.

from ibmi-oss-docs.

kadler avatar kadler commented on August 27, 2024

My guess is that you need to adjust the logging configuration with the opened log file, since it probably holds a handle to the original sys.stdout or sys.stderr even though you've replaced them.

You might want to try calling logging.basicConfig before calling any logging functions and see if that fixes it, eg.

import logging
import sys

logIFSFileName = '/path/to/log/file.txt'
sys.stdout = sys.stderr = open(logIFSFileName, 'w')
logging.basicConfig(stream=sys.stdout)

from ibmi-oss-docs.

sgonchigar avatar sgonchigar commented on August 27, 2024

It worked with one exception. If there is syntax error. it got reported in QPRINT.
example:
QPRINT output.
File "/home/sgonchigar/python/test_logging_v1.py", line 22
^
SyntaxError: unexpected EOF while parsing

from ibmi-oss-docs.

kadler avatar kadler commented on August 27, 2024

Well the problem there is that the syntax error detection happens before the code is run, so the code to do the redirect hasn't run yet.

You could use something like tee instead, which will redirect stdout to a log file and stdout, eg.

QSH CMD('python3 myscript.py 2>&1 | tee myfile.log')

The above example would redirect all output from myscript.py to myfile.log as well as sending it to stdout for the job.

from ibmi-oss-docs.

sgonchigar avatar sgonchigar commented on August 27, 2024

Thank you. That worked!

from ibmi-oss-docs.

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.