public static void setActionEventInfo(String eventType, String description) { LogContext context = LogContext.current(); if (context != null) { context.setEventType(eventType); context.setEventDescription(description); } }
@Override public String toString() { return new StringBuilder("LogCtxt[acct=").append(getCallingAccountId()) .append("; user=") .append(getCallingUserId()) .append("; id=") .append(logContextId) .append("]") .toString(); } }
@PostConstruct public void init() { LogContext.init(entityMgr); } }
@Override public Object onEnterContext(boolean reentry) { if (!reentry && LogContext.current() == null) { LogContext.registerSystemLogContextOnceOnly(); } return null; }
public static LogContext registerSystemLogContextOnceOnly() { try { LogContext context = s_currentContext.get(); if (context == null) { return register(null, null, User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, UUID.randomUUID().toString()); } assert context.getCallingUserId() == User.UID_SYSTEM : "You are calling a very specific method that registers a one time system context. This method is meant for background threads that does processing."; return context; } catch (Exception e) { s_logger.error("Failed to register the system log context.", e); throw new CloudRuntimeException("Failed to register system log context", e); } }
/** * This method should only be called if you can propagate the context id * from another LogContext. * * @param callingUser calling user * @param callingAccount calling account * @param contextId context id propagated from another call context * @return LogContext */ public static LogContext register(User callingUser, Account callingAccount, String contextId) { return register(callingUser, callingAccount, null, null, contextId); }
public static LogContext registerPlaceHolderContext() { LogContext context = new LogContext(0, 0, UUID.randomUUID().toString()); s_currentContext.set(context); return context; }
public void putContextParameters(Map<String, String> details) { if (details == null) return; for (Map.Entry<String, String> entry : details.entrySet()) { putContextParameter(entry.getKey(), entry.getValue()); } }
public static LogContext current() { LogContext context = s_currentContext.get(); if (context == null) { context = registerSystemLogContextOnceOnly(); } return context; }
public String getCallingUserUuid() { return getCallingUser().getUuid(); }
public String getCallingAccountUuid() { return getCallingAccount().getUuid(); }
public static LogContext register(User callingUser, Account callingAccount) { return register(callingUser, callingAccount, UUID.randomUUID().toString()); }
protected static LogContext register(User callingUser, Account callingAccount, Long userId, Long accountId, String contextId) { LogContext callingContext = null; if (userId == null || accountId == null) { callingContext = new LogContext(callingUser, callingAccount, contextId); } else { callingContext = new LogContext(userId, accountId, contextId); } s_currentContext.set(callingContext); MDC.put("logcontextid", UuidUtils.first(contextId)); if (s_logger.isTraceEnabled()) { s_logger.trace("Registered for log: " + callingContext); } return callingContext; }
public static LogContext register(long callingUserId, long callingAccountId) throws CloudAuthenticationException { Account account = s_entityMgr.findById(Account.class, callingAccountId); if (account == null) { throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, Long.toString(callingAccountId)); } User user = s_entityMgr.findById(User.class, callingUserId); if (user == null) { throw new CloudAuthenticationException("The user is no longer current.").add(User.class, Long.toString(callingUserId)); } return register(user, account); }
public static LogContext register(long callingUserId, long callingAccountId, String contextId) throws CloudAuthenticationException { Account account = s_entityMgr.findById(Account.class, callingAccountId); if (account == null) { throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, Long.toString(callingAccountId)); } User user = s_entityMgr.findById(User.class, callingUserId); if (user == null) { throw new CloudAuthenticationException("The user is no longer current.").add(User.class, Long.toString(callingUserId)); } return register(user, account, contextId); }
public static LogContext register(String callingUserUuid, String callingAccountUuid) { Account account = s_entityMgr.findByUuid(Account.class, callingAccountUuid); if (account == null) { throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, callingAccountUuid); } User user = s_entityMgr.findByUuid(User.class, callingUserUuid); if (user == null) { throw new CloudAuthenticationException("The user is no longer current.").add(User.class, callingUserUuid); } return register(user, account); }