Comments (3)
My solution is
class Transcript(object):
def __init__(self, filename):
self.terminal = sys.stdout
self.logfile = open(filename, "w")
def write(self, message):
self.terminal.write(message)
self.terminal.flush()
self.logfile.write(message)
self.logfile.flush()
def flush(self):
# this flush method is needed for python 3 compatibility.
# this handles the flush command by doing nothing.
# you might want to specify some extra behavior here.
pass
def start(filename):
"""Start transcript, appending print output to given filename"""
sys.stdout = Transcript(filename)
def stop():
"""Stop transcript and return print functionality to normal"""
sys.stdout.logfile.close()
sys.stdout = sys.stdout.terminal
start('filename')
main()
stop()
from autogen.
speaking of this, could add a feature to also save all print
to a file at the same time?
from autogen.
`
import sys
import logging
class LoggerWriter:
def init(self, level):
self.logger = logging.getLogger()
self.level = level
self.message = ''
def write(self, message):
if '\n' in message:
self.message += message.rstrip('\n')
if self.message:
self.logger.log(self.level, self.message)
self.message = ''
else:
self.message += message
def flush(self):
pass
def isatty(self):
return False
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setFormatter(logging.Formatter('%(message)s'))
file_handler = logging.FileHandler('myapp.log', 'w')
file_handler.setFormatter(logging.Formatter('%(message)s'))
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
fmt = 'Thinking .... - %(message)s'
formatter = logging.Formatter(fmt)
file_handler.setFormatter(formatter)
sys.stdout = LoggerWriter(logging.INFO)
sys.stderr = LoggerWriter(logging.ERROR)
if name == 'main':
print("This will go", end=" ")
print("to the log file")
`
from autogen.
Related Issues (20)
- [Bug]: lfs tracking HOT 2
- [Bug]: RAG pipeline not updating contexts after 1st query [RAG] HOT 4
- PLEASE FIX CONFIG_LIST HOT 11
- [Bug]: TypeError: Object of type WindowsPath is not JSON serializable HOT 2
- [Issue]: Fail to import RetrieveUserProxyAgent - ImportError: Please install dependencies first. HOT 2
- [Bug]: [CAP} Directory service does not detect other Directories in standalone mode.
- [Bug]: Autobuild .save() doesn't record Function/Tools config information HOT 1
- [Bug]: docs/tutorial/code-executors Docker Execution Doesn't Work HOT 2
- [.Net][Feature Request]: Mistral AI support
- [Bug]: invalid request: agent message content is empty HOT 1
- [Feature Request]: MessageTransform when token limit is exceeded. HOT 6
- [Bug]: Transformations Printing HOT 1
- [Issue]: GitHub - Discord link HOT 28
- [Bug]: doc bug? unclear how to make autogen studio work with Azure OpenAI HOT 3
- [Issue]: TypeError: Completions.create() got an unexpected keyword argument 'headers' HOT 1
- [Issue]: I run LLM through FastChat, and use ChatGLM3 for my LLM. When execute skills will report: NameError: name 'tool_call' is not define
- [.Net][Feature Request]: Ollama API support
- [Feature Request]: Web Surfer Agent should support custom base url and headers. HOT 1
- [Issue]: `runtime_logging` only logs last chat in async groupchat conversations HOT 3
- [Issue]: Improve llm_config validity check in ConversableAgent
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autogen.