Re: [openstack-dev] Logging and traceback at same time.

2016-02-13 Thread joehuang
Hi, Doug,

Partly agree with you that " Tracebacks should be logged for errors the 
application can't recover from." From maintenance perspective, if some 
exception happened, the engineer needs to find out what causes the exception 
and decide to do some work to prevent more sever issue occurred. There are many 
different ways lead to the same exception, only know exception is not enough, 
even how the route leads to the exception is also very important information 
for cloud maintenance. That's the importance to record the trace-back and 
context information.

Best Regards
Chaoyi Huang ( Joe Huang )

-Original Message-
From: Doug Hellmann [mailto:d...@doughellmann.com] 
Sent: Wednesday, February 03, 2016 11:47 PM
To: openstack-dev
Subject: Re: [openstack-dev] Logging and traceback at same time.

Excerpts from Khayam Gondal's message of 2016-02-03 11:28:52 +0500:
> Is there a way to do logging the information and traceback at the same time. 
> Currently I am doing it like this.
> 
>  
> 
>  
> 
> LOG.error(_LE('Record already exists: %(exception)s '
> 
>  '\n %(traceback)'),
> 
>{'exception': e1},
> 
>{'traceback': traceback.print_stack()}).
> 
>  
> 
> Let me know if this is correct way?
> 
> Regards

You've had a couple of responses with tips for how to log the traceback.
Before you adopt those approaches, please consider whether you actually need it 
or not, though.

Tracebacks should be logged for errors the application can't recover from. They 
shouldn't be logged for user errors, warnings, or errors that an operator can 
fix without changing source code. Errors the operator can handle should be 
logged with details about what happened, but not the traceback.

Our logging guidelines are available at
http://specs.openstack.org/openstack/openstack-specs/specs/log-guidelines.html

Doug

__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


Re: [openstack-dev] Logging and traceback at same time.

2016-02-03 Thread Julien Danjou
On Wed, Feb 03 2016, Khayam Gondal wrote:

> Is there a way to do logging the information and traceback at the same
> Let me know if this is correct way?

Pass exc_info=True in your LOG.() call.

-- 
Julien Danjou
;; Free Software hacker
;; https://julien.danjou.info


signature.asc
Description: PGP signature
__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


Re: [openstack-dev] Logging and traceback at same time.

2016-02-03 Thread Sean McGinnis
On Wed, Feb 03, 2016 at 02:46:28PM +0800, 王华 wrote:
> You can use LOG.exception.

Yes, I highly recommend using LOG.exception in this case. That is
exactly what it's used for. LOG.exception is pretty much exactly like
LOG.error, but with the additional behavior that it will log out the
details of whatever exception is currently in scope.

> 
> Regards,
> Wanghua
> 
> On Wed, Feb 3, 2016 at 2:28 PM, Khayam Gondal 
> wrote:
> 
> > Is there a way to do logging the information and traceback at the same
> > time. Currently I am doing it like this.
> >
> >
> >
> >
> >
> > LOG.error(_LE('Record already exists: %(exception)s '
> >
> >  '\n %(traceback)'),
> >
> >{'exception': e1},
> >
> >{'traceback': traceback.print_stack()}).
> >
> >
> >
> > Let me know if this is correct way?
> >
> > Regards
> >
> > __
> > OpenStack Development Mailing List (not for usage questions)
> > Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
> > http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
> >
> >

> __
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


Re: [openstack-dev] Logging and traceback at same time.

2016-02-03 Thread Sean McGinnis
On Wed, Feb 03, 2016 at 10:36:55AM +0100, Julien Danjou wrote:
> On Wed, Feb 03 2016, Khayam Gondal wrote:
> 
> > Is there a way to do logging the information and traceback at the same
> > Let me know if this is correct way?
> 
> Pass exc_info=True in your LOG.() call.

Ooo, great tip!

> 
> -- 
> Julien Danjou
> ;; Free Software hacker
> ;; https://julien.danjou.info



> __
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


Re: [openstack-dev] Logging and traceback at same time.

2016-02-03 Thread Doug Hellmann
Excerpts from Khayam Gondal's message of 2016-02-03 11:28:52 +0500:
> Is there a way to do logging the information and traceback at the same time. 
> Currently I am doing it like this.
> 
>  
> 
>  
> 
> LOG.error(_LE('Record already exists: %(exception)s '
> 
>  '\n %(traceback)'),
> 
>{'exception': e1},
> 
>{'traceback': traceback.print_stack()}).
> 
>  
> 
> Let me know if this is correct way?
> 
> Regards

You've had a couple of responses with tips for how to log the traceback.
Before you adopt those approaches, please consider whether you actually
need it or not, though.

Tracebacks should be logged for errors the application can't recover
from. They shouldn't be logged for user errors, warnings, or errors
that an operator can fix without changing source code. Errors the
operator can handle should be logged with details about what happened,
but not the traceback.

Our logging guidelines are available at
http://specs.openstack.org/openstack/openstack-specs/specs/log-guidelines.html

Doug

__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


Re: [openstack-dev] Logging and traceback at same time.

2016-02-03 Thread Joshua Harlow

Sean McGinnis wrote:

On Wed, Feb 03, 2016 at 02:46:28PM +0800, 王华 wrote:

You can use LOG.exception.


Yes, I highly recommend using LOG.exception in this case. That is
exactly what it's used for. LOG.exception is pretty much exactly like
LOG.error, but with the additional behavior that it will log out the
details of whatever exception is currently in scope.


Not pretty much, it is ;)

https://hg.python.org/cpython/file/b4cbecbc0781/Lib/logging/__init__.py#l1305 



'''
def exception(self, msg, *args, **kwargs):
kwargs['exc_info'] = True
self.error(msg, *args, **kwargs)
'''

-Josh




Regards,
Wanghua

On Wed, Feb 3, 2016 at 2:28 PM, Khayam Gondal
wrote:


Is there a way to do logging the information and traceback at the same
time. Currently I am doing it like this.





LOG.error(_LE('Record already exists: %(exception)s '

  '\n %(traceback)'),

{'exception': e1},

{'traceback': traceback.print_stack()}).



Let me know if this is correct way?

Regards

__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev





__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev



__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


Re: [openstack-dev] Logging and traceback at same time.

2016-02-02 Thread 王华
You can use LOG.exception.

Regards,
Wanghua

On Wed, Feb 3, 2016 at 2:28 PM, Khayam Gondal 
wrote:

> Is there a way to do logging the information and traceback at the same
> time. Currently I am doing it like this.
>
>
>
>
>
> LOG.error(_LE('Record already exists: %(exception)s '
>
>  '\n %(traceback)'),
>
>{'exception': e1},
>
>{'traceback': traceback.print_stack()}).
>
>
>
> Let me know if this is correct way?
>
> Regards
>
> __
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
__
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev