#
# Define a peculiar logging profile for Silverpeas in JBoss/Wildfly
#

echo Define a peculiar logging profile for Silverpeas

if (outcome == success) of /subsystem=logging/logging-profile=silverpeas:read-resource
  /subsystem=logging/logging-profile=silverpeas:remove
end-if

# Add the logging profile Silverpeas
/subsystem=logging/logging-profile=silverpeas:add

if (outcome != success) of /subsystem=logging/logging-profile=silverpeas/pattern-formatter=DEFAULT:read-resource
    /subsystem=logging/logging-profile=silverpeas/pattern-formatter=DEFAULT:add(pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n")
end-if

if (outcome != success) of /subsystem=logging/logging-profile=silverpeas/pattern-formatter=BASIC:read-resource
    /subsystem=logging/logging-profile=silverpeas/pattern-formatter=BASIC:add(pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %s%e%n")
end-if

# Start batch commands

batch

# Add the size rotating file handlers
# For global traces
/subsystem=logging/logging-profile=silverpeas/size-rotating-file-handler=TRACE_LOG_FILE:add(level="ALL", named-formatter=DEFAULT, file={"path"=>"${SILVERPEAS_LOG}/silverpeas-trace.log"}, append=true, max-backup-index=${SILVERPEAS_LOG_BACKUP_MAX}, rotate-size=${SILVERPEAS_LOG_BACKUP_SIZE}, autoflush=true)

# For errors
/subsystem=logging/logging-profile=silverpeas/size-rotating-file-handler=ERROR_LOG_FILE:add(level="ERROR", named-formatter=DEFAULT, file={"path"=>"${SILVERPEAS_LOG}/silverpeas-error.log"}, append=true, max-backup-index=${SILVERPEAS_LOG_BACKUP_MAX}, rotate-size=${SILVERPEAS_LOG_BACKUP_SIZE}, autoflush=true)

# For groups synchronization with remote directory
/subsystem=logging/logging-profile=silverpeas/size-rotating-file-handler=GROUP_SYNC_LOG_FILE:add(level="INFO", named-formatter=BASIC, file={"path"=>"${SILVERPEAS_LOG}/silverpeas-group_sync.log"}, append=true, max-backup-index=${SILVERPEAS_LOG_BACKUP_MAX}, rotate-size=${SILVERPEAS_LOG_BACKUP_SIZE}, autoflush=true)

# For full domain synchronization with remote directory
/subsystem=logging/logging-profile=silverpeas/size-rotating-file-handler=DOMAIN_SYNC_LOG_FILE:add(level="INFO", named-formatter=BASIC, file={"path"=>"${SILVERPEAS_LOG}/silverpeas-domain_sync.log"}, append=true, max-backup-index=${SILVERPEAS_LOG_BACKUP_MAX}, rotate-size=${SILVERPEAS_LOG_BACKUP_SIZE}, autoflush=true)

# For workflow all reassignment tasks
/subsystem=logging/logging-profile=silverpeas/size-rotating-file-handler=WF_REASSIGNMENT_LOG_FILE:add(level="ALL", named-formatter=BASIC, file={"path"=>"${SILVERPEAS_LOG}/silverpeas-workflow-reassignment.log"}, append=true, max-backup-index=${SILVERPEAS_LOG_BACKUP_MAX}, rotate-size=${SILVERPEAS_LOG_BACKUP_SIZE}, autoflush=true)

# Configure the logging asynchronous handlers (by default they aren't used; they are defined in the case some users want asynchronous logging)
/subsystem=logging/logging-profile=silverpeas/async-handler=ASYNC_TRACE_LOG_HANDLER:add(level="ALL",queue-length=1048576,overflow-action=BLOCK,subhandlers=["TRACE_LOG_FILE"])
/subsystem=logging/logging-profile=silverpeas/async-handler=ASYNC_ERROR_LOG_HANDLER:add(level="ERROR",queue-length=1048576,overflow-action=BLOCK,subhandlers=["ERROR_LOG_FILE"])

# Create a logger for Silverpeas: it will take all the texts coming from the Silverpeas root category.
/subsystem=logging/logging-profile=silverpeas/logger=silverpeas:add(level=${SILVERPEAS_LOGGING_LEVEL},handlers=[ASYNC_TRACE_LOG_HANDLER,ASYNC_ERROR_LOG_HANDLER])
/subsystem=logging/logging-profile=silverpeas/logger=silverpeas:write-attribute(name=use-parent-handlers, value=false)

# Create a logger for groups synchronization in domain
/subsystem=logging/logging-profile=silverpeas/logger=silverpeas.core.admin.domain.synchro.group:add(level="INFO",handlers=[GROUP_SYNC_LOG_FILE])
/subsystem=logging/logging-profile=silverpeas/logger=silverpeas.core.admin.domain.synchro.group:write-attribute(name=use-parent-handlers, value=false)

# Create a logger for full domain synchronization
/subsystem=logging/logging-profile=silverpeas/logger=silverpeas.core.admin.domain.synchro.domain:add(level="${SILVERPEAS_LOGGING_LEVEL}",handlers=[DOMAIN_SYNC_LOG_FILE])
/subsystem=logging/logging-profile=silverpeas/logger=silverpeas.core.admin.domain.synchro.domain:write-attribute(name=use-parent-handlers, value=false)

# Create a logger for workflow all reassignment tasks
/subsystem=logging/logging-profile=silverpeas/logger=silverpeas.components.processmanager.reassignment:add(level="${SILVERPEAS_LOGGING_LEVEL}",handlers=[WF_REASSIGNMENT_LOG_FILE])
/subsystem=logging/logging-profile=silverpeas/logger=silverpeas.components.processmanager.reassignment:write-attribute(name=use-parent-handlers, value=false)

# For jboss_output.log
# Change COLOR_PATTERN to Standard Pattern for jboss-output.log
/subsystem=logging/console-handler=CONSOLE:write-attribute(name="named-formatter",value="PATTERN")

# Run the batch commands
run-batch
