Dear all,
I have a class object define in a groovy file named NewUser as below :
import org.apache.log4j.Logger
import org.apache.log4j.Level
class NewUser{
NewUser(Issue issue, boolean Prod)
{
log.setLevel(Level.DEBUG)
}
}
I need to record different log information from that class but when setting the log.SetLevel, I get an error saying :
No such property: log for class: ServiceRequest.NewUser
Any idea why it cannot find the log property ?
regards
Hello @Mathis Hellensberg , I find out the issue.
The way you describe to initiate the Log object creation is only available for use in InLine script.
In my case my class is define in a script file and the way to initiate the log creation is to decorate the class with the syntax @Log4j and the log objects gets available globally
regards
serge
Nice, the more you know :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This should work:
import org.apache.log4j.Logger
import org.apache.log4j.Level
class NewUser{
NewUser(Issue issue, boolean Prod) {
def log = Logger.getLogger(NewUser.class)
log.setLevel(Level.DEBUG)
log.debug("hello world!")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Mathis Hellensberg , it does not work.
I have a red cross saying unexpected token :-( at the time I enter the line :
log.setLevel(Level.DEBUG)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm I tested that this worked for me (Jira 8.6.1):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import org.apache.log4j.Level
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject("SD-47")
class NewUser {
NewUser(Issue issue, boolean Prod) {
def log = Logger.getLogger(NewUser.class)
log.setLevel(Level.DEBUG)
log.debug("hello world!")
}
}
def test = new NewUser(issue, false)
log.info(test)
Do you have anything else in your script? Where are you using the script? Is it a post-function, a listener or?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I get the following exception when the script run :
groovy.lang.MissingPropertyException: No such property: log for class: ServiceRequest.NewUser at ServiceRequest.NewUser.InviteUser(NewUser.groovy:163) at ServiceRequest.NewUser$InviteUser.call(Unknown Source) at Script42.run(Script42.groovy:88)
My newUser class instance creation is done from the InLine script area of a post-function in a worflow .
here is the content of the class :
package ServiceRequest
import MsGraphApi.Helper
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.CommentManager
import groovy.json.*
import groovyx.net.*
import groovyx.net.http.*
import static groovy.json.JsonOutput.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import org.apache.log4j.Logger
import org.apache.log4j.Level
class NewUser{
Helper apiHelper
Issue refIssue
//Field defienition constant to be read from issue
String emailFieldName="Email Address" //10523
String FnameFieldName="First Name"
String LnameFieldName="Last Name"
String AgencyFieldName="Agency"
String emailFieldValue=""
String agencyFieldValue=""
String FnameFieldValue=""
String LnameFieldValue=""
String GroupId_Member_To_Add
CommentManager commentMgr=ComponentAccessor.getCommentManager()
NewUser(Issue issue, boolean Prod)
{
def log = Logger.getLogger(NewUser.class)
log.setLevel(Level.DEBUG)
apiHelper=new Helper(Prod,"RLX-DIGITAL")
refIssue=issue
def customFieldMgr=ComponentAccessor.getCustomFieldManager()
def emailField =customFieldMgr.getCustomFieldObjects().findByName(emailFieldName)
emailFieldValue=refIssue.getCustomFieldValue(emailField)
def FnameField =customFieldMgr.getCustomFieldObjects().findByName(FnameFieldName)
FnameFieldValue=refIssue.getCustomFieldValue(FnameField)
def LnameField =customFieldMgr.getCustomFieldObjects().findByName(LnameFieldName)
LnameFieldValue=refIssue.getCustomFieldValue(LnameField)
def AgencyField =customFieldMgr.getCustomFieldObjects().findByName(AgencyFieldName)
agencyFieldValue=refIssue.getCustomFieldValue(AgencyField)
if (Prod) //If we are in Prodution we get group ID as expected
GetGroupId(agencyFieldValue)
else // Not in prod we test it agains a Test AD account
GroupId_Member_To_Add= GRP_TEST_AGENCY_ITECOR_ID
}
// Main field property return methods
public String GetToken(){return apiHelper.Token}
public String GetEmailValue(){return emailFieldValue}
public String GetFirstNameValue(){return FnameFieldValue}
public String GeLastNameValue(){return LnameFieldValue}
public String GeLAgencyValue(){return agencyFieldValue}
public String GetGroupId(){return GroupId_Member_To_Add}
/*============================================================
Method: MapGroupFromAgency
Identifiy groups ID to which user need to be added
============================================================*/
String GetGroupId(String Agency){
.......
}
/*============================================================
Method: InviteUser
Send invitation to user for joining group
============================================================*/
public boolean InviteUser(){
boolean userInvited=true
boolean userAddedtoGrp=false
boolean userCreated=false
// get user id
String userId= apiHelper.inviteUser(apiHelper.Token,emailFieldValue,FnameFieldValue,LnameFieldValue)
if (userId == null || userId.trim().isEmpty()) {
log.error("ITECOR SCRIPT : User failure to be added as guest in active directory [$emailFieldValue]")
}
else
{
userCreated=true
log.debug("ITECOR SCRIPT : User to invite : " + emailFieldValue)
log.debug("ITECOR SCRIPT : User ID to invite created : " + userId)
log.debug("ITECOR SCRIPT : ISSUE STATUS : " + refIssue.status.name)
// add user to group sample
userAddedtoGrp=apiHelper.addUserToGroup(apiHelper.Token,userId,GroupId_Member_To_Add)
//log.debug("ITECOR SCRIPT : User added to group : " + userAddedtoGrp.toString())
if (userAddedtoGrp){
def reportMsg="""
*Default application access request *\n\n
Dear [~${refIssue.reporter.getName()}], Your request has been assigned to our Team.\n
*Status :* Pending for invitation approvment.\n
An invitation email has been sent to user *$emailFieldValue*\n
Thanks to let us know when *$FnameFieldValue* *$LnameFieldValue* has access to requested application
\n Regards\n Service Desk Team"""
commentMgr.create(refIssue,refIssue.getAssignee(),reportMsg,true)
}
else{
log.debug("ITECOR SCRIPT : Failed adding user to group")
}
}
if (userAddedtoGrp && userInvited)
{
log.debug("ITECOR SCRIPT : User onboarding succesfully completed : " )
userInvited=true
}
else
{
userInvited=false
log.debug("ITECOR SCRIPT : User onboarding NOT completed [userId: $userCreated, [AddToGroup : $userAddedtoGrp] " )
}
userInvited
}
}
The exception is raised at the execution of the first log entry find in the InviteUser method . Seems that the log object is not visible inside a Method of the class which need to use it.
Thanks for help
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm this error "ServiceRequest.NewUser$InviteUser.call(Unknown Source) at Script42.run(Script42.groovy:88)" is beacuse you just have "........" at line 88.
Can you fix that and post the new error?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No the ..... at line 88 is because I have removed some sensitive data before posting the code in this forum..
Seems to me that the log object is not visible inside the method
any idea ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.