from __future__ import unicode_literals, print_function

from twisted.internet.task import react

from eliot.logwriter import ThreadedFileWriter
from eliot import Message, Logger, addDestination


_logger = Logger()



def main(reactor):
    print("Logging to example-eliot.log...")
    logWriter = ThreadedFileWriter(open("example-eliot.log", "ab"), reactor)
    addDestination(logWriter)

    # Manually start the service. Normally we'd register ThreadedFileWriter
    # with the usual Twisted Service/Application infrastructure.
    logWriter.startService()

    # Log a message:
    Message.new(value="hello", another=1).write(_logger)

    # Manually stop the service.
    done = logWriter.stopService()
    return done


if __name__ == '__main__':
    react(main, [])

from __future__ import unicode_literals, print_function

from twisted.internet.task import react

from eliot.logwriter import ThreadedFileWriter
from eliot import Message, Logger


_logger = Logger()



def main(reactor):
    print("Logging to example-eliot.log...")
    logWriter = ThreadedFileWriter(open("example-eliot.log", "ab"), reactor)

    # Manually start the service, which will add it as a
    # destination. Normally we'd register ThreadedFileWriter with the usual
    # Twisted Service/Application infrastructure.
    logWriter.startService()

    # Log a message:
    Message.new(value="hello", another=1).write(_logger)

    # Manually stop the service.
    done = logWriter.stopService()
    return done


if __name__ == '__main__':
    react(main, [])

Fix bug where the service was added as a destination one time too many.
Fix bug where the service was added as a destination one time too many.

  from __future__ import unicode_literals, print_function
  
  from twisted.internet.task import react
  
  from eliot.logwriter import ThreadedFileWriter
- from eliot import Message, Logger, addDestination
+ from eliot import Message, Logger
  
  
  _logger = Logger()
  
  
  
  def main(reactor):
      print("Logging to example-eliot.log...")
      logWriter = ThreadedFileWriter(open("example-eliot.log", "ab"), reactor)
-     addDestination(logWriter)
  
-     # Manually start the service. Normally we'd register ThreadedFileWriter
+     # Manually start the service, which will add it as a
+     # destination. Normally we'd register ThreadedFileWriter with the usual
-     # with the usual Twisted Service/Application infrastructure.
+     # Twisted Service/Application infrastructure.
      logWriter.startService()
  
      # Log a message:
      Message.new(value="hello", another=1).write(_logger)
  
      # Manually stop the service.
      done = logWriter.stopService()
      return done
  
  
  if __name__ == '__main__':
      react(main, [])
  
Fix bug where the service was added as a destination one time too many.
## Code Before:
from __future__ import unicode_literals, print_function

from twisted.internet.task import react

from eliot.logwriter import ThreadedFileWriter
from eliot import Message, Logger, addDestination


_logger = Logger()



def main(reactor):
    print("Logging to example-eliot.log...")
    logWriter = ThreadedFileWriter(open("example-eliot.log", "ab"), reactor)
    addDestination(logWriter)

    # Manually start the service. Normally we'd register ThreadedFileWriter
    # with the usual Twisted Service/Application infrastructure.
    logWriter.startService()

    # Log a message:
    Message.new(value="hello", another=1).write(_logger)

    # Manually stop the service.
    done = logWriter.stopService()
    return done


if __name__ == '__main__':
    react(main, [])

## Instruction:
Fix bug where the service was added as a destination one time too many.
## Code After:
from __future__ import unicode_literals, print_function

from twisted.internet.task import react

from eliot.logwriter import ThreadedFileWriter
from eliot import Message, Logger


_logger = Logger()



def main(reactor):
    print("Logging to example-eliot.log...")
    logWriter = ThreadedFileWriter(open("example-eliot.log", "ab"), reactor)

    # Manually start the service, which will add it as a
    # destination. Normally we'd register ThreadedFileWriter with the usual
    # Twisted Service/Application infrastructure.
    logWriter.startService()

    # Log a message:
    Message.new(value="hello", another=1).write(_logger)

    # Manually stop the service.
    done = logWriter.stopService()
    return done


if __name__ == '__main__':
    react(main, [])
