How to access log for confluence when writing code in scriptrunner?
Asked by Mouna Hammoudi:

I am writing code in scriptrunner and logging some information but what I am logging is too long, so how can I access the full confluence log?

![Capture.PNG](/t5/image/serverpage/image-id/266323i9989991DEC631F7A/image-size/large?v=v2&px=999 "Capture.PNG")

Here is a picture of my log above, only the first 300 lines are shown as you can see above.

Here is my code below:  

```
import com.atlassian.confluence.links.OutgoingLink

import com.atlassian.confluence.pages.Page

import com.atlassian.confluence.pages.PageManager

import com.atlassian.confluence.spaces.Space

import com.atlassian.confluence.spaces.SpaceManager

import com.atlassian.sal.api.component.ComponentLocator

import org.apache.log4j.Logger

import com.atlassian.confluence.user.UserAccessor

import com.atlassian.sal.api.user.UserKey

SpaceManager spaceManager = ComponentLocator.getComponent(SpaceManager)

PageManager pageManager = ComponentLocator.getComponent(PageManager)

UserAccessor userAccessor = ComponentLocator.getComponent(UserAccessor)

Space space = spaceManager.getSpace("IWIKI")

for (Page page : pageManager.getPages(space, true)) {

    if(page.getCreator()==null){

            log.warn(page.toString()+",null")

    }

    else{

            String userID=page.getCreator().getName()

            String fullName =userAccessor.getUserByKey(page.getCreator().getKey()).getFullName()

            log.warn(page.toString()+","+userID+","+fullName+","+page.getLastModificationDate())

    }

   

}
```

<br />

<br />


Answers:
author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi [@Mouna Hammoudi](/t5/user/viewprofilepage/user-id/4688138)

The ScriptRunner console output has only a limit of up to 300 lines; the rest would be truncated.

I suggest writing your result to a file, i.e. something like:-

```
import com.atlassian.confluence.links.OutgoingLink
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.user.UserKey

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)
def userAccessor = ComponentLocator.getComponent(UserAccessor)
def space = spaceManager.getSpace("IWIKI")

pageManager.getPages(space, true).each { page ->

    if(!page.creator){

         log.warn("${page.toString()},null")

    } else {
           def userID = page.creator.name
           def fullName = userAccessor.getUserByKey(page.creator.key).fullName
           def file = new File('/temp/result.log')
           def fileWriter = new FileWriter(file) 
           fileWriter.write("${page.toString(), ${userID}, ${fullName}, ${page.lastModificationDate}")
           fileWriter.close()
    }
}
```

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

comments: author: Evgenii
body: As an alternative, I can suggest concatenation to one loooooong string, with \<br/\> delimiters, and then output it to Result tab.


author: Mouna Hammoudi
body: [@Ram Kumar Aravindakshan _Adaptavist_](/t5/user/viewprofilepage/user-id/2988015)

Is it not possible to access a log instead of writing it to a file?

I clicked on**Logging and Profiling** under the admin section of Confluence and I got the following:

![Capture.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/266331i362FE57A2A82C05F/image-size/large?v=v2&px=999 "Capture.PNG")

I specified the same string highlighted in yellow as my log destination.

Here is the code:

```


import com.atlassian.confluence.links.OutgoingLink

import com.atlassian.confluence.pages.Page

import com.atlassian.confluence.pages.PageManager

import com.atlassian.confluence.spaces.Space

import com.atlassian.confluence.spaces.SpaceManager

import com.atlassian.sal.api.component.ComponentLocator

import org.apache.log4j.Logger

import com.atlassian.confluence.user.UserAccessor

import com.atlassian.sal.api.user.UserKey



SpaceManager spaceManager = ComponentLocator.getComponent(SpaceManager)

PageManager pageManager = ComponentLocator.getComponent(PageManager)

UserAccessor userAccessor = ComponentLocator.getComponent(UserAccessor)

def log = Logger.getLogger("com.atlassian.bonnie.search.extractor")

Space space = spaceManager.getSpace("IWIKI")

for (Page page : pageManager.getPages(space, true)) {

    if(page.getCreator()==null){

            log.warn(page.toString()+",null")

    }

    else{

            String userID=page.getCreator().getName()

            String fullName =userAccessor.getUserByKey(page.getCreator().getKey()).getFullName()

            log.warn("mouna"+","+page.toString()+","+userID+","+fullName+","+page.getLastModificationDate())

    }

   

}?
```


author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi [@Mouna Hammoudi](/t5/user/viewprofilepage/user-id/4688138)

In your last comment, you asked:-
> Is it not possible to access a log instead of writing it to a file?

To answer your question, yes, it is possible to write to a log if that is your preference.

If you intend to pass it all into the logs, I would suggest adding a Marker into the logs so it would be easier to trace something like:-

```
import com.atlassian.confluence.links.OutgoingLink
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.user.UserKey

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)
def userAccessor = ComponentLocator.getComponent(UserAccessor)
def space = spaceManager.getSpace("IWIKI")

pageManager.getPages(space, true).each { page ->

    if(!page.creator){

         log.warn("${page.toString()},null")

    } else {
           def userID = page.creator.name
           def fullName = userAccessor.getUserByKey(page.creator.key).fullName
           log.warn "===================== START ======================"
           log.warn "mouna, ${page.toString(), ${userID}, ${fullName}, ${page.lastModificationDate}"
           log.warn "=====================  END  ======================"

    }
}
```

You will then need to look into the **atlassian-confluence.log** file to check the output printed.

However, if you expect all the results to be displayed in the ScriptRunner Console, that will not happen, as it will truncate the result.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram


author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi [@Mouna Hammoudi](/t5/user/viewprofilepage/user-id/4688138)

Has your question been answered?

If yes, please accept the answer.

Thank you and Kind regards,  
Ram


Tags: confluence-server

log

scriptrunner

server