[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RESEND PATCH 07/12] golang/xenlight: add logging conveniences for within xenlight


  • To: Nick Rosbrook <rosbrookn@xxxxxxxxx>
  • From: George Dunlap <George.Dunlap@xxxxxxxxxx>
  • Date: Fri, 18 Jun 2021 13:17:07 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6fHtGz2JESlVjuScKJTP5Z1l76LA/i3gzCifQWsztXQ=; b=EwY/3MyFzG8oA1pWU9e7HK1eoHBX87BgjxvhG0bcZESJDLVPSs0ioOX0cvplfRBDhyzbl3ZSpBrMbxeUUU418gzm49Oa6gJ5GJI7JiA0cgCseEJ7RdM+gtPN5iqxkc6mixJhp73BqmJFqrulF/N0ZQQFrEBfO34wsSWBsySwINSIDm8kHam1cdHlfiZ8/0ZV0RUxrednd3vW26LekD+zIvFmTLsaMaLkZFECPUOcvIhywGCfSnB/Z48gj2e84R8U2UrBxP4fiqdUnxDlJEZrar7NA9n+sfoCXbPh+e9jeekn9/B41tki8JyhbBIV0bW4bMCC6JJAFXkS/QYeSQdH1w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lno6nbYN5oEdfgJ+vsXkMNF57SFUpu61vAMdv1o11qwBXA8xfq+HtXWI2W2dQbZe70/z7tKw4GorgvjhAfVdswjXalgD+rKcvGfkVqFnlXmc5+xO0tf9hNlhKPE3bz7Jv7w9Y1pjeQY77mApSHdoXacn115qNkpzRQGY+vcx1WZXx6ujeayxzJxBVD7sEEOFtCoktUvvX+PsJhTCotGEwI1Di8RJyN1OolWYduXS+p5Azjwlfb3mEBuOY9jgct/z+UHdf5vbFNKBJQYZjzVLi4n2H56uzHxi4lCvK4agNGv9GrwRq8ICf92zQGLQxeSG0naMiPdoxNYYD6t4bia7yQ==
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 18 Jun 2021 13:17:16 +0000
  • Ironport-hdrordr: A9a23:pt2IWKjllDpjItuGpA3vqxFmk3BQX2p13DAbv31ZSRFFG/FwyP re/sjzhCWE6wr5BktBpTnZAtjwfZvdnaQFmLX5To3SLDUO2VHYbr2KgrGSvgEIdxeOkdK1kJ 0QDZSWBeeaMbEYt7e+3ODbKadd/DDvysnB6YixrgYJPGVXguNbnnhE426gYxJLrWJ9dOIE/e +nl7B6Tk2bCA8qh6qAdx84tu74zeEjdqiKXTc2QzocrCWehzKh77D3VzKC2A0Fbj9JybA+tU DYjg3Q/MyYwrWG4y6Z81WWw4VdmdPnxNcGLteLkNIpJjLljRvtTJh9WoeFoCs+rIiUmREXeZ j30lEd1vZImivsl1KO0EDQMs7boWwTAkrZuAalaL3Y0JHErXwBepZ8bMliA2jkAgIbzaNBOe RwrjykXtNsfGb9tTW46N7SWx5wkE2o5XIkjO4IlnRaFZATcblLsOUkjQJo+Tg7bWnHAa0cYa ZT5fvnlbhrmJKhHjrkl3gqxMbpUmU4Hx+ATERHssuJ0yJOlHQ8y0cD3sQQknoJ6Zp4EvB/lq f5G7UtkKsLQt4dbKp7CutEScyrCnbVSRaJNG6JO1zoGKwOJnqIoZ/q57c+4v2sZfUzvdsPcV T6IR9lXEsJCgrT4OG1ret2GyH2MSiAtG7Wu7ZjDrBCy/TBrZTQQFm+dGw=
  • Ironport-sdr: GmhFe+IPf3xdOPdoHEp4qGgVke3EhlFl7+baJO14VWgJ8QBZcO9kfJlS/tA0AtmiyhE5pRbeAW S6CIDEqkivWOrXHx9Cdnxz9c84kGAihY+Uv9AKXf7VAt7vyMSUNES2ZHshOnXnMSeSdz1SfGqQ JSf8gl8jWffpzFaAfgQ3adWlQaVLWRBXCndvhtZ1Gc2ztDonv9Ug/OFD33MAyyyWJoWcFLvrW4 HlXyacnC1tgKHwCVHgNcZuFgSI1+wg4lZ2Fy6LeYPUfIqLinxw+X5m9+ehVYyjrmW0o7n7BX93 riU=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHXUNy8b62kbX7r3k+nzGZDJK+dZqsZ5r2A
  • Thread-topic: [RESEND PATCH 07/12] golang/xenlight: add logging conveniences for within xenlight


> On May 24, 2021, at 9:36 PM, Nick Rosbrook <rosbrookn@xxxxxxxxx> wrote:
> 
> Add some logging methods to Context to provide easy use of the
> Contenxt's xentoollog_logger. These are not exported, but the LogLevel
> type is so that a later commit can allow the Context's log level to be
> configurable.
> 
> Becuase cgo does not support calling C functions with variable
> arguments, e.g. xtl_log, add an xtl_log_wrap function to the cgo preamble
> that accepts an already formatted string, and handle the formatting in
> Go.
> 
> Signed-off-by: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>

Looks good.  One comment:

> ---
> tools/golang/xenlight/xenlight.go | 45 +++++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
> 
> diff --git a/tools/golang/xenlight/xenlight.go 
> b/tools/golang/xenlight/xenlight.go
> index fc3eb0bf3f..f68d7b6e97 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -32,6 +32,15 @@ static const libxl_childproc_hooks childproc_hooks = { 
> .chldowner = libxl_sigchl
> void xenlight_set_chldproc(libxl_ctx *ctx) {
>       libxl_childproc_setmode(ctx, &childproc_hooks, NULL);
> }
> +
> +void xtl_log_wrap(struct xentoollog_logger *logger,
> +               xentoollog_level level,
> +               int errnoval,
> +               const char *context,
> +               const char *msg)
> +{
> +    xtl_log(logger, level, errnoval, context, "%s", msg);
> +}
> */
> import "C"
> 
> @@ -192,6 +201,42 @@ func (ctx *Context) Close() error {
>       return nil
> }
> 
> +// LogLevel represents an xentoollog_level, and can be used to configre the 
> log
> +// level of a Context's logger.
> +type LogLevel int
> +
> +const (
> +     //LogLevelNone     LogLevel = C.XTL_NONE

Why are we not defining this one?  Don’t we want to be able to disable logging 
entirely?

> +     LogLevelDebug    LogLevel = C.XTL_DEBUG
> +     LogLevelVerbose  LogLevel = C.XTL_VERBOSE
> +     LogLevelDetail   LogLevel = C.XTL_DETAIL
> +     LogLevelProgress LogLevel = C.XTL_PROGRESS
> +     LogLevelInfo     LogLevel = C.XTL_INFO
> +     LogLevelNotice   LogLevel = C.XTL_NOTICE
> +     LogLevelWarn     LogLevel = C.XTL_WARN
> +     LogLevelError    LogLevel = C.XTL_ERROR
> +     LogLevelCritical LogLevel = C.XTL_CRITICAL
> +     //LogLevelNumLevels LogLevel = C.XTL_NUM_LEVELS
> +)
> +
> +func (ctx *Context) log(lvl LogLevel, errnoval int, format string, a 
> ...interface{}) {
> +     msg := C.CString(fmt.Sprintf(format, a...))
> +     defer C.free(unsafe.Pointer(msg))
> +     context := C.CString("xenlight")
> +     defer C.free(unsafe.Pointer(context))

Hmm, allocating and freeing a fixed string every time seems pretty wasteful.  
Would it make more sense to either use a static C string in the CGo code at the 
top instead?  Or if not, to make context a global variable we allocate once at 
the package level and re-use?

Also, is ‘xenlight’ informative enough?  I haven’t looked at the other 
“context” strings; would “go-xenlight” or something be better?

> +
> +     C.xtl_log_wrap((*C.xentoollog_logger)(unsafe.Pointer(ctx.logger)),
> +             C.xentoollog_level(lvl), C.int(errnoval), context, msg)
> +}

I think we want to make it possible long-term to configure your own logger or 
have no logger at all; so maybe we should add a `if (ctx.logger == nil) 
return;` at then top?

Other than that looks good, thanks!

 -George

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.