Write to logger using Velocity

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Write to logger using Velocity

Jason Clemons
Hello, can someone please give me an example of how to write to a log using Velocity code?

I'd really like to write a text file, but at this point any logging would be tremendously helpful, thanks
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

vmassol
Administrator

On 25 Aug 2014 at 18:02:12, Jason Clemons ([hidden email](mailto:[hidden email])) wrote:

> Hello, can someone please give me an example of how to write to a log using Velocity code?
>
> I'd really like to write a text file, but at this point any logging would be tremendously helpful, thanks

Since XWiki 6.1:
http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting

Thanks
-Vincent
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

Jason Clemons
Thanks for the response Vincent, I did see this article, but I'm having trouble figuring out how to implement it.  Ultimately, I just want the equivalent of "Console.Log('foobar');" for some debugging code.  I don't want to setup a full blown logging architecture or anything heavy for my wiki.  Is there some simple example on the link you provided that I'm not interpreting correctly?

> On Aug 25, 2014, at 9:18 AM, "[hidden email]" <[hidden email]> wrote:
>
>
>> On 25 Aug 2014 at 18:02:12, Jason Clemons ([hidden email](mailto:[hidden email])) wrote:
>>
>> Hello, can someone please give me an example of how to write to a log using Velocity code?
>>
>> I'd really like to write a text file, but at this point any logging would be tremendously helpful, thanks
>
> Since XWiki 6.1:
> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
>
> Thanks
> -Vincent
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

vmassol
Administrator
 



On 25 Aug 2014 at 18:26:28, Jason Clemons ([hidden email](mailto:[hidden email])) wrote:

> Thanks for the response Vincent, I did see this article, but I'm having trouble figuring out how to implement it. Ultimately, I just want the equivalent of "Console.Log('foobar');" for some debugging code. I don't want to setup a full blown logging architecture or anything heavy for my wiki. Is there some simple example on the link you provided that I'm not interpreting correctly?

If you’re inside XWiki then you already have logging configured! There’s nothing to do except use it as show in the link I gave. Which is exactly the equivalent of "Console.Log('foobar');”.

Thanks
-Vincent

> > On Aug 25, 2014, at 9:18 AM, "[hidden email]" wrote:
> >
> >
> >> On 25 Aug 2014 at 18:02:12, Jason Clemons ([hidden email](mailto:[hidden email])) wrote:
> >>
> >> Hello, can someone please give me an example of how to write to a log using Velocity code?
> >>
> >> I'd really like to write a text file, but at this point any logging would be tremendously helpful, thanks
> >
> > Since XWiki 6.1:
> > http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
> >
> > Thanks
> > -Vincent
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

Jason Clemons
Thanks again for taking time to respond, forgive my ignorance..I still don't really "get it" could you possibly show me an example of the syntax for writing to the logs from within my Velocity code?  In groovy I can simply write:

{{groovy}}
System.out.println("foobar")
{{/groovy}}

I'm just having an issue figuring out the velocity equivalent...


> On Aug 25, 2014, at 9:56 AM, "[hidden email]" <[hidden email]> wrote:
>
>  
>
>
>
>> On 25 Aug 2014 at 18:26:28, Jason Clemons ([hidden email](mailto:[hidden email])) wrote:
>>
>> Thanks for the response Vincent, I did see this article, but I'm having trouble figuring out how to implement it. Ultimately, I just want the equivalent of "Console.Log('foobar');" for some debugging code. I don't want to setup a full blown logging architecture or anything heavy for my wiki. Is there some simple example on the link you provided that I'm not interpreting correctly?
>
> If you’re inside XWiki then you already have logging configured! There’s nothing to do except use it as show in the link I gave. Which is exactly the equivalent of "Console.Log('foobar');”.
>
> Thanks
> -Vincent
>
>>> On Aug 25, 2014, at 9:18 AM, "[hidden email]" wrote:
>>>
>>>
>>>> On 25 Aug 2014 at 18:02:12, Jason Clemons ([hidden email](mailto:[hidden email])) wrote:
>>>>
>>>> Hello, can someone please give me an example of how to write to a log using Velocity code?
>>>>
>>>> I'd really like to write a text file, but at this point any logging would be tremendously helpful, thanks
>>>
>>> Since XWiki 6.1:
>>> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
>>>
>>> Thanks
>>> -Vincent
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

jerem
Hello,

{{velocity}}
#set($logger = $services.logging.getLogger("My script"))

$logger.info("foobar")

{{/velocity}}


This is exactly what is on the page linked by Vincent, just with a more
similar "look" to your own sample.
"My script" is just an informative name of the logger you create. You could
use $doc.name for instance.

It's not much more complex, and it's really more clean than
System.out.println ;-)

BR,
Jeremie


2014-08-25 19:33 GMT+02:00 Jason Clemons <[hidden email]>:

> Thanks again for taking time to respond, forgive my ignorance..I still
> don't really "get it" could you possibly show me an example of the syntax
> for writing to the logs from within my Velocity code?  In groovy I can
> simply write:
>
> {{groovy}}
> System.out.println("foobar")
> {{/groovy}}
>
> I'm just having an issue figuring out the velocity equivalent...
>
>
> > On Aug 25, 2014, at 9:56 AM, "[hidden email]" <[hidden email]>
> wrote:
> >
> >
> >
> >
> >
> >> On 25 Aug 2014 at 18:26:28, Jason Clemons ([hidden email]
> (mailto:[hidden email])) wrote:
> >>
> >> Thanks for the response Vincent, I did see this article, but I'm having
> trouble figuring out how to implement it. Ultimately, I just want the
> equivalent of "Console.Log('foobar');" for some debugging code. I don't
> want to setup a full blown logging architecture or anything heavy for my
> wiki. Is there some simple example on the link you provided that I'm not
> interpreting correctly?
> >
> > If you’re inside XWiki then you already have logging configured! There’s
> nothing to do except use it as show in the link I gave. Which is exactly
> the equivalent of "Console.Log('foobar');”.
> >
> > Thanks
> > -Vincent
> >
> >>> On Aug 25, 2014, at 9:18 AM, "[hidden email]" wrote:
> >>>
> >>>
> >>>> On 25 Aug 2014 at 18:02:12, Jason Clemons ([hidden email]
> (mailto:[hidden email])) wrote:
> >>>>
> >>>> Hello, can someone please give me an example of how to write to a log
> using Velocity code?
> >>>>
> >>>> I'd really like to write a text file, but at this point any logging
> would be tremendously helpful, thanks
> >>>
> >>> Since XWiki 6.1:
> >>>
> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
> >>>
> >>> Thanks
> >>> -Vincent
> > _______________________________________________
> > users mailing list
> > [hidden email]
> > http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

Jason Clemons
That's why I said "forgive my ignorance" in my previous email :)

I was thrown off by defining the "informative name".  Is that a persistent value once defined? Or is just something that gets added to the log entry?

> On Aug 25, 2014, at 11:28 PM, "Jeremie BOUSQUET" <[hidden email]> wrote:
>
> Hello,
>
> {{velocity}}
> #set($logger = $services.logging.getLogger("My script"))
>
> $logger.info("foobar")
>
> {{/velocity}}
>
>
> This is exactly what is on the page linked by Vincent, just with a more
> similar "look" to your own sample.
> "My script" is just an informative name of the logger you create. You could
> use $doc.name for instance.
>
> It's not much more complex, and it's really more clean than
> System.out.println ;-)
>
> BR,
> Jeremie
>
>
> 2014-08-25 19:33 GMT+02:00 Jason Clemons <[hidden email]>:
>
>> Thanks again for taking time to respond, forgive my ignorance..I still
>> don't really "get it" could you possibly show me an example of the syntax
>> for writing to the logs from within my Velocity code?  In groovy I can
>> simply write:
>>
>> {{groovy}}
>> System.out.println("foobar")
>> {{/groovy}}
>>
>> I'm just having an issue figuring out the velocity equivalent...
>>
>>
>>>> On Aug 25, 2014, at 9:56 AM, "[hidden email]" <[hidden email]>
>>> wrote:
>>>
>>>
>>>
>>>
>>>
>>>> On 25 Aug 2014 at 18:26:28, Jason Clemons ([hidden email]
>> (mailto:[hidden email])) wrote:
>>>>
>>>> Thanks for the response Vincent, I did see this article, but I'm having
>> trouble figuring out how to implement it. Ultimately, I just want the
>> equivalent of "Console.Log('foobar');" for some debugging code. I don't
>> want to setup a full blown logging architecture or anything heavy for my
>> wiki. Is there some simple example on the link you provided that I'm not
>> interpreting correctly?
>>>
>>> If you’re inside XWiki then you already have logging configured! There’s
>> nothing to do except use it as show in the link I gave. Which is exactly
>> the equivalent of "Console.Log('foobar');”.
>>>
>>> Thanks
>>> -Vincent
>>>
>>>>> On Aug 25, 2014, at 9:18 AM, "[hidden email]" wrote:
>>>>>
>>>>>
>>>>>> On 25 Aug 2014 at 18:02:12, Jason Clemons ([hidden email]
>> (mailto:[hidden email])) wrote:
>>>>>>
>>>>>> Hello, can someone please give me an example of how to write to a log
>> using Velocity code?
>>>>>>
>>>>>> I'd really like to write a text file, but at this point any logging
>> would be tremendously helpful, thanks
>>>>>
>>>>> Since XWiki 6.1:
>> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
>>>>>
>>>>> Thanks
>>>>> -Vincent
>>> _______________________________________________
>>> users mailing list
>>> [hidden email]
>>> http://lists.xwiki.org/mailman/listinfo/users
>> _______________________________________________
>> users mailing list
>> [hidden email]
>> http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

Jason Clemons
So sorry, but one more question..since I'm new to Xwiki, and all of it's underlying architecture (I'm a .net guy) I'm sure this is something that I'm doing wrong, but I figured I'd ask.

When I copy and paste the code you provided below into a page (in the "source" section)  the page and the script section renders without error on the page, but the output literally says "$logger.info("foobar")" on the page.

I would expect no visible output, but to see a log entry, am I missing something?

> On Aug 26, 2014, at 7:39 AM, "Jason Clemons" <[hidden email]> wrote:
>
> That's why I said "forgive my ignorance" in my previous email :)
>
> I was thrown off by defining the "informative name".  Is that a persistent value once defined? Or is just something that gets added to the log entry?
>
>> On Aug 25, 2014, at 11:28 PM, "Jeremie BOUSQUET" <[hidden email]> wrote:
>>
>> Hello,
>>
>> {{velocity}}
>> #set($logger = $services.logging.getLogger("My script"))
>>
>> $logger.info("foobar")
>>
>> {{/velocity}}
>>
>>
>> This is exactly what is on the page linked by Vincent, just with a more
>> similar "look" to your own sample.
>> "My script" is just an informative name of the logger you create. You could
>> use $doc.name for instance.
>>
>> It's not much more complex, and it's really more clean than
>> System.out.println ;-)
>>
>> BR,
>> Jeremie
>>
>>
>> 2014-08-25 19:33 GMT+02:00 Jason Clemons <[hidden email]>:
>>
>>> Thanks again for taking time to respond, forgive my ignorance..I still
>>> don't really "get it" could you possibly show me an example of the syntax
>>> for writing to the logs from within my Velocity code?  In groovy I can
>>> simply write:
>>>
>>> {{groovy}}
>>> System.out.println("foobar")
>>> {{/groovy}}
>>>
>>> I'm just having an issue figuring out the velocity equivalent...
>>>
>>>
>>>>> On Aug 25, 2014, at 9:56 AM, "[hidden email]" <[hidden email]>
>>>> wrote:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> On 25 Aug 2014 at 18:26:28, Jason Clemons ([hidden email]
>>> (mailto:[hidden email])) wrote:
>>>>>
>>>>> Thanks for the response Vincent, I did see this article, but I'm having
>>> trouble figuring out how to implement it. Ultimately, I just want the
>>> equivalent of "Console.Log('foobar');" for some debugging code. I don't
>>> want to setup a full blown logging architecture or anything heavy for my
>>> wiki. Is there some simple example on the link you provided that I'm not
>>> interpreting correctly?
>>>>
>>>> If you’re inside XWiki then you already have logging configured! There’s
>>> nothing to do except use it as show in the link I gave. Which is exactly
>>> the equivalent of "Console.Log('foobar');”.
>>>>
>>>> Thanks
>>>> -Vincent
>>>>
>>>>>> On Aug 25, 2014, at 9:18 AM, "[hidden email]" wrote:
>>>>>>
>>>>>>
>>>>>>> On 25 Aug 2014 at 18:02:12, Jason Clemons ([hidden email]
>>> (mailto:[hidden email])) wrote:
>>>>>>>
>>>>>>> Hello, can someone please give me an example of how to write to a log
>>> using Velocity code?
>>>>>>>
>>>>>>> I'd really like to write a text file, but at this point any logging
>>> would be tremendously helpful, thanks
>>>>>>
>>>>>> Since XWiki 6.1:
>>> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
>>>>>>
>>>>>> Thanks
>>>>>> -Vincent
>>>> _______________________________________________
>>>> users mailing list
>>>> [hidden email]
>>>> http://lists.xwiki.org/mailman/listinfo/users
>>> _______________________________________________
>>> users mailing list
>>> [hidden email]
>>> http://lists.xwiki.org/mailman/listinfo/users
>> _______________________________________________
>> users mailing list
>> [hidden email]
>> http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

jerem
In reply to this post by Jason Clemons
2014-08-26 16:39 GMT+02:00 Jason Clemons <[hidden email]>:

> That's why I said "forgive my ignorance" in my previous email :)
>
> I was thrown off by defining the "informative name".  Is that a persistent
> value once defined? Or is just something that gets added to the log entry?
>

That's something that may get added to the log entries, but I didn't check
so I'm not sure it's done by default ...


>
> > On Aug 25, 2014, at 11:28 PM, "Jeremie BOUSQUET" <
> [hidden email]> wrote:
> >
> > Hello,
> >
> > {{velocity}}
> > #set($logger = $services.logging.getLogger("My script"))
> >
> > $logger.info("foobar")
> >
> > {{/velocity}}
> >
> >
> > This is exactly what is on the page linked by Vincent, just with a more
> > similar "look" to your own sample.
> > "My script" is just an informative name of the logger you create. You
> could
> > use $doc.name for instance.
> >
> > It's not much more complex, and it's really more clean than
> > System.out.println ;-)
> >
> > BR,
> > Jeremie
> >
> >
> > 2014-08-25 19:33 GMT+02:00 Jason Clemons <[hidden email]>:
> >
> >> Thanks again for taking time to respond, forgive my ignorance..I still
> >> don't really "get it" could you possibly show me an example of the
> syntax
> >> for writing to the logs from within my Velocity code?  In groovy I can
> >> simply write:
> >>
> >> {{groovy}}
> >> System.out.println("foobar")
> >> {{/groovy}}
> >>
> >> I'm just having an issue figuring out the velocity equivalent...
> >>
> >>
> >>>> On Aug 25, 2014, at 9:56 AM, "[hidden email]" <[hidden email]
> >
> >>> wrote:
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>> On 25 Aug 2014 at 18:26:28, Jason Clemons ([hidden email]
> >> (mailto:[hidden email])) wrote:
> >>>>
> >>>> Thanks for the response Vincent, I did see this article, but I'm
> having
> >> trouble figuring out how to implement it. Ultimately, I just want the
> >> equivalent of "Console.Log('foobar');" for some debugging code. I don't
> >> want to setup a full blown logging architecture or anything heavy for my
> >> wiki. Is there some simple example on the link you provided that I'm not
> >> interpreting correctly?
> >>>
> >>> If you’re inside XWiki then you already have logging configured!
> There’s
> >> nothing to do except use it as show in the link I gave. Which is exactly
> >> the equivalent of "Console.Log('foobar');”.
> >>>
> >>> Thanks
> >>> -Vincent
> >>>
> >>>>> On Aug 25, 2014, at 9:18 AM, "[hidden email]" wrote:
> >>>>>
> >>>>>
> >>>>>> On 25 Aug 2014 at 18:02:12, Jason Clemons ([hidden email]
> >> (mailto:[hidden email])) wrote:
> >>>>>>
> >>>>>> Hello, can someone please give me an example of how to write to a
> log
> >> using Velocity code?
> >>>>>>
> >>>>>> I'd really like to write a text file, but at this point any logging
> >> would be tremendously helpful, thanks
> >>>>>
> >>>>> Since XWiki 6.1:
> >>
> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
> >>>>>
> >>>>> Thanks
> >>>>> -Vincent
> >>> _______________________________________________
> >>> users mailing list
> >>> [hidden email]
> >>> http://lists.xwiki.org/mailman/listinfo/users
> >> _______________________________________________
> >> users mailing list
> >> [hidden email]
> >> http://lists.xwiki.org/mailman/listinfo/users
> > _______________________________________________
> > users mailing list
> > [hidden email]
> > http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

Valdis Vītoliņš
In reply to this post by Jason Clemons
You need to say that following will be velocity script with
opening/closing tags like this:

{{velocity}}
#set($logger = $services.logging.getLogger("My script"))
$logger.info("foobar")
{{/velocity}}

Valdis


_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

Jason Clemons
I have exactly that in my page, that's why I was confused :)

> On Aug 26, 2014, at 8:17 AM, "Valdis Vītoliņš" <[hidden email]> wrote:
>
> You need to say that following will be velocity script with
> opening/closing tags like this:
>
> {{velocity}}
> #set($logger = $services.logging.getLogger("My script"))
> $logger.info("foobar")
> {{/velocity}}
>
> Valdis
>
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

jerem
In reply to this post by Jason Clemons
2014-08-26 17:08 GMT+02:00 Jason Clemons <[hidden email]>:

> So sorry, but one more question..since I'm new to Xwiki, and all of it's
> underlying architecture (I'm a .net guy) I'm sure this is something that
> I'm doing wrong, but I figured I'd ask.
>
> When I copy and paste the code you provided below into a page (in the
> "source" section)  the page and the script section renders without error on
> the page, but the output literally says "$logger.info("foobar")" on the
> page.
>
> I would expect no visible output, but to see a log entry, am I missing
> something?
>

Same for me, that's why it's bad to provide samples without actually
testing them :)

In fact I don't see any "getLogger" method in $services.logging, which you
can check in the Scripting Reference page [1].

Double-checking myself, it's normal in my case as Vincent it was added in
6.1, and I'm not in 6.1, so nothing abnormal here ...

In your case if you are on 6.1 and it doesn't work, I would suspect that
maybe you copy-pasted this code into a page in wysiwyg editor instead of
wiki editor.
If you have wysiwyg by default and you're not an advanced user, you can
choose insert / macro, choose the "velocity" macro, and enter the content
between {{velocity}} in the macro content.
Or you can switch to advanced user and/or wiki editor (sorry, miss time to
find the urls in xwiki.org ;-) )


[1] - http://platform.xwiki.org/xwiki/bin/view/SRD/Navigation



>
> > On Aug 26, 2014, at 7:39 AM, "Jason Clemons" <[hidden email]>
> wrote:
> >
> > That's why I said "forgive my ignorance" in my previous email :)
> >
> > I was thrown off by defining the "informative name".  Is that a
> persistent value once defined? Or is just something that gets added to the
> log entry?
> >
> >> On Aug 25, 2014, at 11:28 PM, "Jeremie BOUSQUET" <
> [hidden email]> wrote:
> >>
> >> Hello,
> >>
> >> {{velocity}}
> >> #set($logger = $services.logging.getLogger("My script"))
> >>
> >> $logger.info("foobar")
> >>
> >> {{/velocity}}
> >>
> >>
> >> This is exactly what is on the page linked by Vincent, just with a more
> >> similar "look" to your own sample.
> >> "My script" is just an informative name of the logger you create. You
> could
> >> use $doc.name for instance.
> >>
> >> It's not much more complex, and it's really more clean than
> >> System.out.println ;-)
> >>
> >> BR,
> >> Jeremie
> >>
> >>
> >> 2014-08-25 19:33 GMT+02:00 Jason Clemons <[hidden email]>:
> >>
> >>> Thanks again for taking time to respond, forgive my ignorance..I still
> >>> don't really "get it" could you possibly show me an example of the
> syntax
> >>> for writing to the logs from within my Velocity code?  In groovy I can
> >>> simply write:
> >>>
> >>> {{groovy}}
> >>> System.out.println("foobar")
> >>> {{/groovy}}
> >>>
> >>> I'm just having an issue figuring out the velocity equivalent...
> >>>
> >>>
> >>>>> On Aug 25, 2014, at 9:56 AM, "[hidden email]" <
> [hidden email]>
> >>>> wrote:
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>> On 25 Aug 2014 at 18:26:28, Jason Clemons ([hidden email]
> >>> (mailto:[hidden email])) wrote:
> >>>>>
> >>>>> Thanks for the response Vincent, I did see this article, but I'm
> having
> >>> trouble figuring out how to implement it. Ultimately, I just want the
> >>> equivalent of "Console.Log('foobar');" for some debugging code. I don't
> >>> want to setup a full blown logging architecture or anything heavy for
> my
> >>> wiki. Is there some simple example on the link you provided that I'm
> not
> >>> interpreting correctly?
> >>>>
> >>>> If you’re inside XWiki then you already have logging configured!
> There’s
> >>> nothing to do except use it as show in the link I gave. Which is
> exactly
> >>> the equivalent of "Console.Log('foobar');”.
> >>>>
> >>>> Thanks
> >>>> -Vincent
> >>>>
> >>>>>> On Aug 25, 2014, at 9:18 AM, "[hidden email]" wrote:
> >>>>>>
> >>>>>>
> >>>>>>> On 25 Aug 2014 at 18:02:12, Jason Clemons ([hidden email]
> >>> (mailto:[hidden email])) wrote:
> >>>>>>>
> >>>>>>> Hello, can someone please give me an example of how to write to a
> log
> >>> using Velocity code?
> >>>>>>>
> >>>>>>> I'd really like to write a text file, but at this point any logging
> >>> would be tremendously helpful, thanks
> >>>>>>
> >>>>>> Since XWiki 6.1:
> >>>
> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
> >>>>>>
> >>>>>> Thanks
> >>>>>> -Vincent
> >>>> _______________________________________________
> >>>> users mailing list
> >>>> [hidden email]
> >>>> http://lists.xwiki.org/mailman/listinfo/users
> >>> _______________________________________________
> >>> users mailing list
> >>> [hidden email]
> >>> http://lists.xwiki.org/mailman/listinfo/users
> >> _______________________________________________
> >> users mailing list
> >> [hidden email]
> >> http://lists.xwiki.org/mailman/listinfo/users
> > _______________________________________________
> > users mailing list
> > [hidden email]
> > http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

Jason Clemons
This is something new to 6.1?  I'm not on 6.1 yet, maybe that's why?

> On Aug 26, 2014, at 8:21 AM, "Jeremie BOUSQUET" <[hidden email]> wrote:
>
> 2014-08-26 17:08 GMT+02:00 Jason Clemons <[hidden email]>:
>
>> So sorry, but one more question..since I'm new to Xwiki, and all of it's
>> underlying architecture (I'm a .net guy) I'm sure this is something that
>> I'm doing wrong, but I figured I'd ask.
>>
>> When I copy and paste the code you provided below into a page (in the
>> "source" section)  the page and the script section renders without error on
>> the page, but the output literally says "$logger.info("foobar")" on the
>> page.
>>
>> I would expect no visible output, but to see a log entry, am I missing
>> something?
>
> Same for me, that's why it's bad to provide samples without actually
> testing them :)
>
> In fact I don't see any "getLogger" method in $services.logging, which you
> can check in the Scripting Reference page [1].
>
> Double-checking myself, it's normal in my case as Vincent it was added in
> 6.1, and I'm not in 6.1, so nothing abnormal here ...
>
> In your case if you are on 6.1 and it doesn't work, I would suspect that
> maybe you copy-pasted this code into a page in wysiwyg editor instead of
> wiki editor.
> If you have wysiwyg by default and you're not an advanced user, you can
> choose insert / macro, choose the "velocity" macro, and enter the content
> between {{velocity}} in the macro content.
> Or you can switch to advanced user and/or wiki editor (sorry, miss time to
> find the urls in xwiki.org ;-) )
>
>
> [1] - http://platform.xwiki.org/xwiki/bin/view/SRD/Navigation
>
>
>
>>
>>>> On Aug 26, 2014, at 7:39 AM, "Jason Clemons" <[hidden email]>
>>> wrote:
>>>
>>> That's why I said "forgive my ignorance" in my previous email :)
>>>
>>> I was thrown off by defining the "informative name".  Is that a
>> persistent value once defined? Or is just something that gets added to the
>> log entry?
>>>
>>>> On Aug 25, 2014, at 11:28 PM, "Jeremie BOUSQUET" <
>> [hidden email]> wrote:
>>>>
>>>> Hello,
>>>>
>>>> {{velocity}}
>>>> #set($logger = $services.logging.getLogger("My script"))
>>>>
>>>> $logger.info("foobar")
>>>>
>>>> {{/velocity}}
>>>>
>>>>
>>>> This is exactly what is on the page linked by Vincent, just with a more
>>>> similar "look" to your own sample.
>>>> "My script" is just an informative name of the logger you create. You
>> could
>>>> use $doc.name for instance.
>>>>
>>>> It's not much more complex, and it's really more clean than
>>>> System.out.println ;-)
>>>>
>>>> BR,
>>>> Jeremie
>>>>
>>>>
>>>> 2014-08-25 19:33 GMT+02:00 Jason Clemons <[hidden email]>:
>>>>
>>>>> Thanks again for taking time to respond, forgive my ignorance..I still
>>>>> don't really "get it" could you possibly show me an example of the
>> syntax
>>>>> for writing to the logs from within my Velocity code?  In groovy I can
>>>>> simply write:
>>>>>
>>>>> {{groovy}}
>>>>> System.out.println("foobar")
>>>>> {{/groovy}}
>>>>>
>>>>> I'm just having an issue figuring out the velocity equivalent...
>>>>>
>>>>>
>>>>>>> On Aug 25, 2014, at 9:56 AM, "[hidden email]" <
>> [hidden email]>
>>>>>> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> On 25 Aug 2014 at 18:26:28, Jason Clemons ([hidden email]
>>>>> (mailto:[hidden email])) wrote:
>>>>>>>
>>>>>>> Thanks for the response Vincent, I did see this article, but I'm
>> having
>>>>> trouble figuring out how to implement it. Ultimately, I just want the
>>>>> equivalent of "Console.Log('foobar');" for some debugging code. I don't
>>>>> want to setup a full blown logging architecture or anything heavy for
>> my
>>>>> wiki. Is there some simple example on the link you provided that I'm
>> not
>>>>> interpreting correctly?
>>>>>>
>>>>>> If you’re inside XWiki then you already have logging configured!
>> There’s
>>>>> nothing to do except use it as show in the link I gave. Which is
>> exactly
>>>>> the equivalent of "Console.Log('foobar');”.
>>>>>>
>>>>>> Thanks
>>>>>> -Vincent
>>>>>>
>>>>>>>> On Aug 25, 2014, at 9:18 AM, "[hidden email]" wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>> On 25 Aug 2014 at 18:02:12, Jason Clemons ([hidden email]
>>>>> (mailto:[hidden email])) wrote:
>>>>>>>>>
>>>>>>>>> Hello, can someone please give me an example of how to write to a
>> log
>>>>> using Velocity code?
>>>>>>>>>
>>>>>>>>> I'd really like to write a text file, but at this point any logging
>>>>> would be tremendously helpful, thanks
>>>>>>>>
>>>>>>>> Since XWiki 6.1:
>> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
>>>>>>>>
>>>>>>>> Thanks
>>>>>>>> -Vincent
>>>>>> _______________________________________________
>>>>>> users mailing list
>>>>>> [hidden email]
>>>>>> http://lists.xwiki.org/mailman/listinfo/users
>>>>> _______________________________________________
>>>>> users mailing list
>>>>> [hidden email]
>>>>> http://lists.xwiki.org/mailman/listinfo/users
>>>> _______________________________________________
>>>> users mailing list
>>>> [hidden email]
>>>> http://lists.xwiki.org/mailman/listinfo/users
>>> _______________________________________________
>>> users mailing list
>>> [hidden email]
>>> http://lists.xwiki.org/mailman/listinfo/users
>> _______________________________________________
>> users mailing list
>> [hidden email]
>> http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

jerem
Yes, quoting Vincent Massol above : "Since XWiki 6.1" ;-)
See also here:
http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HGetaLoggerfromscript

So for < 6.1, I think there must be a solution but right now I don't know
...


2014-08-26 17:25 GMT+02:00 Jason Clemons <[hidden email]>:

> This is something new to 6.1?  I'm not on 6.1 yet, maybe that's why?
>
> > On Aug 26, 2014, at 8:21 AM, "Jeremie BOUSQUET" <
> [hidden email]> wrote:
> >
> > 2014-08-26 17:08 GMT+02:00 Jason Clemons <[hidden email]>:
> >
> >> So sorry, but one more question..since I'm new to Xwiki, and all of it's
> >> underlying architecture (I'm a .net guy) I'm sure this is something that
> >> I'm doing wrong, but I figured I'd ask.
> >>
> >> When I copy and paste the code you provided below into a page (in the
> >> "source" section)  the page and the script section renders without
> error on
> >> the page, but the output literally says "$logger.info("foobar")" on the
> >> page.
> >>
> >> I would expect no visible output, but to see a log entry, am I missing
> >> something?
> >
> > Same for me, that's why it's bad to provide samples without actually
> > testing them :)
> >
> > In fact I don't see any "getLogger" method in $services.logging, which
> you
> > can check in the Scripting Reference page [1].
> >
> > Double-checking myself, it's normal in my case as Vincent it was added in
> > 6.1, and I'm not in 6.1, so nothing abnormal here ...
> >
> > In your case if you are on 6.1 and it doesn't work, I would suspect that
> > maybe you copy-pasted this code into a page in wysiwyg editor instead of
> > wiki editor.
> > If you have wysiwyg by default and you're not an advanced user, you can
> > choose insert / macro, choose the "velocity" macro, and enter the content
> > between {{velocity}} in the macro content.
> > Or you can switch to advanced user and/or wiki editor (sorry, miss time
> to
> > find the urls in xwiki.org ;-) )
> >
> >
> > [1] - http://platform.xwiki.org/xwiki/bin/view/SRD/Navigation
> >
> >
> >
> >>
> >>>> On Aug 26, 2014, at 7:39 AM, "Jason Clemons" <[hidden email]>
> >>> wrote:
> >>>
> >>> That's why I said "forgive my ignorance" in my previous email :)
> >>>
> >>> I was thrown off by defining the "informative name".  Is that a
> >> persistent value once defined? Or is just something that gets added to
> the
> >> log entry?
> >>>
> >>>> On Aug 25, 2014, at 11:28 PM, "Jeremie BOUSQUET" <
> >> [hidden email]> wrote:
> >>>>
> >>>> Hello,
> >>>>
> >>>> {{velocity}}
> >>>> #set($logger = $services.logging.getLogger("My script"))
> >>>>
> >>>> $logger.info("foobar")
> >>>>
> >>>> {{/velocity}}
> >>>>
> >>>>
> >>>> This is exactly what is on the page linked by Vincent, just with a
> more
> >>>> similar "look" to your own sample.
> >>>> "My script" is just an informative name of the logger you create. You
> >> could
> >>>> use $doc.name for instance.
> >>>>
> >>>> It's not much more complex, and it's really more clean than
> >>>> System.out.println ;-)
> >>>>
> >>>> BR,
> >>>> Jeremie
> >>>>
> >>>>
> >>>> 2014-08-25 19:33 GMT+02:00 Jason Clemons <[hidden email]>:
> >>>>
> >>>>> Thanks again for taking time to respond, forgive my ignorance..I
> still
> >>>>> don't really "get it" could you possibly show me an example of the
> >> syntax
> >>>>> for writing to the logs from within my Velocity code?  In groovy I
> can
> >>>>> simply write:
> >>>>>
> >>>>> {{groovy}}
> >>>>> System.out.println("foobar")
> >>>>> {{/groovy}}
> >>>>>
> >>>>> I'm just having an issue figuring out the velocity equivalent...
> >>>>>
> >>>>>
> >>>>>>> On Aug 25, 2014, at 9:56 AM, "[hidden email]" <
> >> [hidden email]>
> >>>>>> wrote:
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>> On 25 Aug 2014 at 18:26:28, Jason Clemons ([hidden email]
> >>>>> (mailto:[hidden email])) wrote:
> >>>>>>>
> >>>>>>> Thanks for the response Vincent, I did see this article, but I'm
> >> having
> >>>>> trouble figuring out how to implement it. Ultimately, I just want the
> >>>>> equivalent of "Console.Log('foobar');" for some debugging code. I
> don't
> >>>>> want to setup a full blown logging architecture or anything heavy for
> >> my
> >>>>> wiki. Is there some simple example on the link you provided that I'm
> >> not
> >>>>> interpreting correctly?
> >>>>>>
> >>>>>> If you’re inside XWiki then you already have logging configured!
> >> There’s
> >>>>> nothing to do except use it as show in the link I gave. Which is
> >> exactly
> >>>>> the equivalent of "Console.Log('foobar');”.
> >>>>>>
> >>>>>> Thanks
> >>>>>> -Vincent
> >>>>>>
> >>>>>>>> On Aug 25, 2014, at 9:18 AM, "[hidden email]" wrote:
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>> On 25 Aug 2014 at 18:02:12, Jason Clemons (
> [hidden email]
> >>>>> (mailto:[hidden email])) wrote:
> >>>>>>>>>
> >>>>>>>>> Hello, can someone please give me an example of how to write to a
> >> log
> >>>>> using Velocity code?
> >>>>>>>>>
> >>>>>>>>> I'd really like to write a text file, but at this point any
> logging
> >>>>> would be tremendously helpful, thanks
> >>>>>>>>
> >>>>>>>> Since XWiki 6.1:
> >>
> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
> >>>>>>>>
> >>>>>>>> Thanks
> >>>>>>>> -Vincent
> >>>>>> _______________________________________________
> >>>>>> users mailing list
> >>>>>> [hidden email]
> >>>>>> http://lists.xwiki.org/mailman/listinfo/users
> >>>>> _______________________________________________
> >>>>> users mailing list
> >>>>> [hidden email]
> >>>>> http://lists.xwiki.org/mailman/listinfo/users
> >>>> _______________________________________________
> >>>> users mailing list
> >>>> [hidden email]
> >>>> http://lists.xwiki.org/mailman/listinfo/users
> >>> _______________________________________________
> >>> users mailing list
> >>> [hidden email]
> >>> http://lists.xwiki.org/mailman/listinfo/users
> >> _______________________________________________
> >> users mailing list
> >> [hidden email]
> >> http://lists.xwiki.org/mailman/listinfo/users
> > _______________________________________________
> > users mailing list
> > [hidden email]
> > http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Write to logger using Velocity

Thomas Mortagne
Administrator
http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HGetaLoggerfromscript
allows logging without programming right but if you don't care about
required right and are admin you can use Groovy to "inject" that
logger for you (there is no pure Velocity solution here since Velocity
API is very simple but also very limited).

Should be something like:

{{groovy}}
logger = org.slf4j.LoggerFactory.getLogger("whatever you want here")
{{/groovy}}

{{velocity}}
$logger.info("foobar")
{{/velocity}}

Alternatively you can replace the xwiki-platform-logging-script jar
file you have in WEB-INF/lib by the 6.1 one you can find in
http://nexus.xwiki.org/nexus/content/groups/public/org/xwiki/platform/xwiki-platform-logging-script/6.1/
and that should work if you are not in a too old version compared to
6.1 (which one is it by the way ?).

On Tue, Aug 26, 2014 at 5:33 PM, Jeremie BOUSQUET
<[hidden email]> wrote:

> Yes, quoting Vincent Massol above : "Since XWiki 6.1" ;-)
> See also here:
> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HGetaLoggerfromscript
>
> So for < 6.1, I think there must be a solution but right now I don't know
> ...
>
>
> 2014-08-26 17:25 GMT+02:00 Jason Clemons <[hidden email]>:
>
>> This is something new to 6.1?  I'm not on 6.1 yet, maybe that's why?
>>
>> > On Aug 26, 2014, at 8:21 AM, "Jeremie BOUSQUET" <
>> [hidden email]> wrote:
>> >
>> > 2014-08-26 17:08 GMT+02:00 Jason Clemons <[hidden email]>:
>> >
>> >> So sorry, but one more question..since I'm new to Xwiki, and all of it's
>> >> underlying architecture (I'm a .net guy) I'm sure this is something that
>> >> I'm doing wrong, but I figured I'd ask.
>> >>
>> >> When I copy and paste the code you provided below into a page (in the
>> >> "source" section)  the page and the script section renders without
>> error on
>> >> the page, but the output literally says "$logger.info("foobar")" on the
>> >> page.
>> >>
>> >> I would expect no visible output, but to see a log entry, am I missing
>> >> something?
>> >
>> > Same for me, that's why it's bad to provide samples without actually
>> > testing them :)
>> >
>> > In fact I don't see any "getLogger" method in $services.logging, which
>> you
>> > can check in the Scripting Reference page [1].
>> >
>> > Double-checking myself, it's normal in my case as Vincent it was added in
>> > 6.1, and I'm not in 6.1, so nothing abnormal here ...
>> >
>> > In your case if you are on 6.1 and it doesn't work, I would suspect that
>> > maybe you copy-pasted this code into a page in wysiwyg editor instead of
>> > wiki editor.
>> > If you have wysiwyg by default and you're not an advanced user, you can
>> > choose insert / macro, choose the "velocity" macro, and enter the content
>> > between {{velocity}} in the macro content.
>> > Or you can switch to advanced user and/or wiki editor (sorry, miss time
>> to
>> > find the urls in xwiki.org ;-) )
>> >
>> >
>> > [1] - http://platform.xwiki.org/xwiki/bin/view/SRD/Navigation
>> >
>> >
>> >
>> >>
>> >>>> On Aug 26, 2014, at 7:39 AM, "Jason Clemons" <[hidden email]>
>> >>> wrote:
>> >>>
>> >>> That's why I said "forgive my ignorance" in my previous email :)
>> >>>
>> >>> I was thrown off by defining the "informative name".  Is that a
>> >> persistent value once defined? Or is just something that gets added to
>> the
>> >> log entry?
>> >>>
>> >>>> On Aug 25, 2014, at 11:28 PM, "Jeremie BOUSQUET" <
>> >> [hidden email]> wrote:
>> >>>>
>> >>>> Hello,
>> >>>>
>> >>>> {{velocity}}
>> >>>> #set($logger = $services.logging.getLogger("My script"))
>> >>>>
>> >>>> $logger.info("foobar")
>> >>>>
>> >>>> {{/velocity}}
>> >>>>
>> >>>>
>> >>>> This is exactly what is on the page linked by Vincent, just with a
>> more
>> >>>> similar "look" to your own sample.
>> >>>> "My script" is just an informative name of the logger you create. You
>> >> could
>> >>>> use $doc.name for instance.
>> >>>>
>> >>>> It's not much more complex, and it's really more clean than
>> >>>> System.out.println ;-)
>> >>>>
>> >>>> BR,
>> >>>> Jeremie
>> >>>>
>> >>>>
>> >>>> 2014-08-25 19:33 GMT+02:00 Jason Clemons <[hidden email]>:
>> >>>>
>> >>>>> Thanks again for taking time to respond, forgive my ignorance..I
>> still
>> >>>>> don't really "get it" could you possibly show me an example of the
>> >> syntax
>> >>>>> for writing to the logs from within my Velocity code?  In groovy I
>> can
>> >>>>> simply write:
>> >>>>>
>> >>>>> {{groovy}}
>> >>>>> System.out.println("foobar")
>> >>>>> {{/groovy}}
>> >>>>>
>> >>>>> I'm just having an issue figuring out the velocity equivalent...
>> >>>>>
>> >>>>>
>> >>>>>>> On Aug 25, 2014, at 9:56 AM, "[hidden email]" <
>> >> [hidden email]>
>> >>>>>> wrote:
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>>>> On 25 Aug 2014 at 18:26:28, Jason Clemons ([hidden email]
>> >>>>> (mailto:[hidden email])) wrote:
>> >>>>>>>
>> >>>>>>> Thanks for the response Vincent, I did see this article, but I'm
>> >> having
>> >>>>> trouble figuring out how to implement it. Ultimately, I just want the
>> >>>>> equivalent of "Console.Log('foobar');" for some debugging code. I
>> don't
>> >>>>> want to setup a full blown logging architecture or anything heavy for
>> >> my
>> >>>>> wiki. Is there some simple example on the link you provided that I'm
>> >> not
>> >>>>> interpreting correctly?
>> >>>>>>
>> >>>>>> If you’re inside XWiki then you already have logging configured!
>> >> There’s
>> >>>>> nothing to do except use it as show in the link I gave. Which is
>> >> exactly
>> >>>>> the equivalent of "Console.Log('foobar');”.
>> >>>>>>
>> >>>>>> Thanks
>> >>>>>> -Vincent
>> >>>>>>
>> >>>>>>>> On Aug 25, 2014, at 9:18 AM, "[hidden email]" wrote:
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>>> On 25 Aug 2014 at 18:02:12, Jason Clemons (
>> [hidden email]
>> >>>>> (mailto:[hidden email])) wrote:
>> >>>>>>>>>
>> >>>>>>>>> Hello, can someone please give me an example of how to write to a
>> >> log
>> >>>>> using Velocity code?
>> >>>>>>>>>
>> >>>>>>>>> I'd really like to write a text file, but at this point any
>> logging
>> >>>>> would be tremendously helpful, thanks
>> >>>>>>>>
>> >>>>>>>> Since XWiki 6.1:
>> >>
>> http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HScripting
>> >>>>>>>>
>> >>>>>>>> Thanks
>> >>>>>>>> -Vincent
>> >>>>>> _______________________________________________
>> >>>>>> users mailing list
>> >>>>>> [hidden email]
>> >>>>>> http://lists.xwiki.org/mailman/listinfo/users
>> >>>>> _______________________________________________
>> >>>>> users mailing list
>> >>>>> [hidden email]
>> >>>>> http://lists.xwiki.org/mailman/listinfo/users
>> >>>> _______________________________________________
>> >>>> users mailing list
>> >>>> [hidden email]
>> >>>> http://lists.xwiki.org/mailman/listinfo/users
>> >>> _______________________________________________
>> >>> users mailing list
>> >>> [hidden email]
>> >>> http://lists.xwiki.org/mailman/listinfo/users
>> >> _______________________________________________
>> >> users mailing list
>> >> [hidden email]
>> >> http://lists.xwiki.org/mailman/listinfo/users
>> > _______________________________________________
>> > users mailing list
>> > [hidden email]
>> > http://lists.xwiki.org/mailman/listinfo/users
>> _______________________________________________
>> users mailing list
>> [hidden email]
>> http://lists.xwiki.org/mailman/listinfo/users
>>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users



--
Thomas Mortagne
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users