I don't know of any modules/classes to identify if the script is running from ArcGIS toolbox vs. Python IDE. However, I have also run into this very thing. Here is my solution.
I have a simple function I wrote to handle this type of thing.
# Function to write info to log file
# passing a value of 1 along with the msg will log in info to a file, otherwise the function will just a print a message
def loginfo(msg, loglevel):
if loglevel == 1:
log = open(logfile,'a')
log.write('\n---------')
log.write(msg)
log.close()
print msg
arcpy.AddMessage(msg)
else:
print msg
arcpy.AddMessage(msg)
return
It's pretty simple function that takes a message string and an integer. It's pretty standard in all my scripts (I should create it as a module/class so I can import it). If you want to use it make sure to create a logfile variable with a path to a file to log to.