All of lore.kernel.org
 help / color / mirror / Atom feed
From: George Dunlap <George.Dunlap@citrix.com>
To: Nick Rosbrook <rosbrookn@gmail.com>
Cc: "xen-devel@lists.xenproject.prg" <xen-devel@lists.xenproject.prg>,
	xen-devel <xen-devel@lists.xenproject.org>,
	Nick Rosbrook <rosbrookn@ainfosec.com>,
	Ian Jackson <iwj@xenproject.org>, Wei Liu <wl@xen.org>
Subject: Re: [RESEND PATCH 07/12] golang/xenlight: add logging conveniences for within xenlight
Date: Fri, 18 Jun 2021 13:17:07 +0000	[thread overview]
Message-ID: <A96AD4DD-35CB-495F-A008-D72A5C2AF45D@citrix.com> (raw)
In-Reply-To: <452aac2489990ac0195c62d8cb820fbe5786c466.1621887506.git.rosbrookn@ainfosec.com>



> On May 24, 2021, at 9:36 PM, Nick Rosbrook <rosbrookn@gmail.com> 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@ainfosec.com>

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

  reply	other threads:[~2021-06-18 13:17 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24 20:36 [RESEND PATCH 00/12] golang/xenlight: domain life cycle support Nick Rosbrook
2021-05-24 20:36 ` [RESEND PATCH 01/12] golang/xenlight: update generated code Nick Rosbrook
2021-06-18 10:30   ` George Dunlap
2021-05-24 20:36 ` [RESEND PATCH 02/12] golang/xenlight: fix StringList toC conversion Nick Rosbrook
2021-06-18 10:51   ` George Dunlap
2021-05-24 20:36 ` [RESEND PATCH 03/12] golang/xenlight: fix string conversion in generated toC functions Nick Rosbrook
2021-06-18 11:00   ` George Dunlap
2021-06-21 16:11     ` Nick Rosbrook
2021-07-01 14:09       ` George Dunlap
2021-07-07 19:29         ` Nick Rosbrook
2021-05-24 20:36 ` [RESEND PATCH 04/12] golang/xenlight: export keyed union interface types Nick Rosbrook
2021-06-18 11:19   ` George Dunlap
2021-05-24 20:36 ` [RESEND PATCH 05/12] golang/xenlight: use struct pointers in keyed union fields Nick Rosbrook
2021-06-18 11:26   ` George Dunlap
2021-05-24 20:36 ` [RESEND PATCH 06/12] golang/xenlight: rename Ctx receivers to ctx Nick Rosbrook
2021-06-18 11:39   ` George Dunlap
2021-05-24 20:36 ` [RESEND PATCH 07/12] golang/xenlight: add logging conveniences for within xenlight Nick Rosbrook
2021-06-18 13:17   ` George Dunlap [this message]
2021-06-18 13:21     ` George Dunlap
2021-06-18 15:26       ` Nick Rosbrook
2021-06-18 16:30         ` George Dunlap
2021-06-18 15:17     ` Nick Rosbrook
2021-06-18 16:28       ` George Dunlap
2021-05-24 20:36 ` [RESEND PATCH 08/12] golang/xenlight: add functional options to configure Context Nick Rosbrook
2021-06-18 14:44   ` George Dunlap
2021-06-18 15:08     ` Nick Rosbrook
2021-06-18 16:18       ` George Dunlap
2021-06-18 17:00         ` Nick Rosbrook
2021-06-18 18:12           ` George Dunlap
2021-05-24 20:36 ` [RESEND PATCH 09/12] golang/xenlight: add DomainDestroy wrapper Nick Rosbrook
2021-06-18 14:47   ` George Dunlap
2021-05-24 20:36 ` [RESEND PATCH 10/12] golang/xenlight: add SendTrigger wrapper Nick Rosbrook
2021-06-18 14:54   ` George Dunlap
2021-05-24 20:36 ` [RESEND PATCH 11/12] golang/xenlight: do not negate ret when converting to Error Nick Rosbrook
2021-06-18 15:13   ` George Dunlap
2021-06-18 15:32     ` Nick Rosbrook
2021-05-24 20:36 ` [RESEND PATCH 12/12] golang/xenlight: add NotifyDomainDeath method to Context Nick Rosbrook
2021-06-18 18:28   ` George Dunlap
2021-06-18 19:31     ` George Dunlap
2021-06-21 21:41       ` Nick Rosbrook
2021-06-17 15:29 ` [RESEND PATCH 00/12] golang/xenlight: domain life cycle support Nick Rosbrook
2021-06-21 15:53 ` George Dunlap
2021-06-21 16:19   ` Nick Rosbrook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=A96AD4DD-35CB-495F-A008-D72A5C2AF45D@citrix.com \
    --to=george.dunlap@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=rosbrookn@ainfosec.com \
    --cc=rosbrookn@gmail.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    --cc=xen-devel@lists.xenproject.prg \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.